1326 - Race
Time Limit: 1 second(s) Memory Limit: 32 MB

Disky and Sooma, two of the biggest mega minds of Bangladesh went to a far country. They ate, coded and wandered around, even in their holidays. They passed several months in this way. But everything has an end. A holy person, Munsiji came into their life. Munsiji took them to derby (horse racing). Munsiji enjoyed the race, but as usual Disky and Sooma did their as usual task instead of passing some romantic moments. They were thinking- in how many ways a race can finish! Who knows, maybe this is their romance!

In a race there are n horses. You have to output the number of ways the race can finish. Note that, more than one horse may get the same position. For example, 2 horses can finish in 3 ways.

  1. Both first
  2. horse1 first and horse2 second
  3. horse2 first and horse1 second

Input

Input starts with an integer T (≤ 1000), denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n ≤ 1000).

Output

For each case, print the case number and the number of ways the race can finish. The result can be very large, print the result modulo 10056.

Sample Input

Output for Sample Input

3

1

2

3

Case 1: 1

Case 2: 3

Case 3: 13


Problem Setter: Md. Mahbubul Hasan
Special Thanks: Shahriar Rouf Nafi, Tanaeem M Moosa, Jane Alam Jan
思路:裸的斯特林数
 1 #include<stdio.h>
2 #include<algorithm>
3 #include<string.h>
4 #include<iostream>
5 using namespace std;
6 typedef long long LL;
7 const LL N= 10056;
8 LL yan[1005][1005];
9 LL STL[1005][1005];
10 LL pp[1005];
11 LL quick(LL n,LL m);
12 int main(void)
13 {
14 int i,j,k;
15 scanf("%d",&k);
16 int s;
17 yan[0][0]=1;
18 for(i=1; i<=1000; i++)
19 {
20 for(j=0; j<=i; j++)
21 {
22 if(j==0||i==j)
23 yan[i][j]=1;
24 else
25 {
26 yan[i][j]=(yan[i-1][j]+yan[i-1][j-1])%N;
27 }
28 }
29 }
30 pp[0]=1;
31 for(i=1;i<=1000;i++)
32 pp[i]=(pp[i-1]*i)%N;
33 memset(STL,0,sizeof(STL));
34 STL[0][0]=1;
35 STL[1][0]=0;
36 STL[1][1]=1;
37 for(i=2; i<=1000; i++)
38 {
39 for(j=1; j<=i; j++)
40 {
41 if(j==1||i==j)
42 STL[i][j]=1;
43 else
44 {
45 STL[i][j]=((STL[i-1][j]*j)%N+STL[i-1][j-1])%N;
46 }
47 }
48 }
49 for(s=1; s<=k; s++)
50 { int x1;
51 scanf("%d",&x1);
52 LL cnt=0;
53 for(i=1; i<=x1; i++)
54 {
55 cnt=(cnt+(STL[x1][i]*pp[i])%N)%N;
56 }
57 printf("Case %d: ",s);
58 printf("%lld\n",cnt);
59 }
60 return 0;
61 }
62
63 LL quick(LL n,LL m)
64 {
65 LL ans=1;n%=N;
66 while(m)
67 {
68 if(m&1)
69 ans=(ans*n)%N;
70 n=(n*n)%N;
71 m/=2;
72 }
73 return ans;
74 }

1326 - Race的更多相关文章

  1. lightOJ 1326 Race(第二类Stirling数)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1326 题意:有n匹马赛跑.问有多少种不同的排名结果.可以有多匹马的排名相同. 思路:排 ...

  2. LightOJ - 1326 - Race(DP)

    链接: https://vjudge.net/problem/LightOJ-1326 题意: Disky and Sooma, two of the biggest mega minds of Ba ...

  3. LightOJ 1326 – Race 第二类Stirling数/

    简单的模板题. 题意:问n匹马出现的不同排名数. 题解:可以使用DP,本质上还是第二类Stirling数(隔板法) #include <stdio.h> #include <iost ...

  4. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. Promise.race

    [Promise.race] 返回最先完成的promise var p1 = new Promise(function(resolve, reject) { setTimeout(resolve, 5 ...

  6. golang中的race检测

    golang中的race检测 由于golang中的go是非常方便的,加上函数又非常容易隐藏go. 所以很多时候,当我们写出一个程序的时候,我们并不知道这个程序在并发情况下会不会出现什么问题. 所以在本 ...

  7. 【BZOJ-2599】Race 点分治

    2599: [IOI2011]Race Time Limit: 70 Sec  Memory Limit: 128 MBSubmit: 2590  Solved: 769[Submit][Status ...

  8. HDU 1326 Box of Bricks(水~平均高度求最少移动砖)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1326 题目大意: 给n堵墙,每个墙的高度不同,求最少移动多少块转使得墙的的高度相同. 解题思路: 找到 ...

  9. hiho #1326 : 有序01字符串

    #1326 : 有序01字符串 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 对于一个01字符串,你每次可以将一个0修改成1,或者将一个1修改成0.那么,你最少需要修改 ...

随机推荐

  1. java的缓冲流及使用Properties集合存取数据(遍历,store,load)

    缓冲流 概述 字节缓冲流:BufferedInputStream,BufferedOutputStream 字符缓冲流:BufferedReader,BufferedWriter 缓冲流原理 缓冲区是 ...

  2. 分布式事务(4)---最终一致性方案之TCC

    分布式事务(1)-理论基础 分布式事务(2)---强一致性分布式事务解决方案 分布式事务(3)---强一致性分布式事务Atomikos实战 强一致性分布式事务解决方案要求参与事务的各个节点的数据时刻保 ...

  3. 利用抖音Cookie充值接口提取支付链接,个人调起原生微信h5支付宝h5支付

    最近开始搞一些个人支付通道的开发,方便个人不用和第三方平台签约就能收款,省去很多流程手续的成本. 然后翻了一下网上并没有太多现成的技术教程,只能自己研究着搞了. 这次要分享的是利用抖音的充值接口,去分 ...

  4. day13 装饰器与语法糖

    day13 装饰器与语法糖 一.装饰器 1.什么是装饰器 装饰器就是装饰别人的工具,具体是指为被装饰者添加新功能 装饰器->函数 被装饰者->函数 2.为何要用装饰器 装饰器的核心思想:( ...

  5. Spark基础:(三)Spark 键值对操作

    1.pair RDD的简介 Spark为包含键值对类型的RDD提供了一些专有的操作,这些RDD就被称为pair RDD 那么如何创建pair RDD呢? 在不同的语言中有着不同的创建方式 在pytho ...

  6. Git(一)【基本使用,集成IDEA,GitHub】

    目录 一.本地库操作 ①基本操作 1.初始化本地库 2.设置用户签名|用户名|邮箱 3.查看本地库状态 4.添加暂存区 5.提交到本地库 6.查看文件modify详情 ②历史版本以及回退 1.查看历史 ...

  7. nodejs-CommonJS规范

    JavaScript 标准参考教程(alpha) 草稿二:Node.js CommonJS规范 GitHub TOP CommonJS规范 来自<JavaScript 标准参考教程(alpha) ...

  8. [php代码审计] Typecho 1.1 -反序列化Cookie数据进行前台Getshell

    环境搭建 源码下载:https://github.com/typecho/typecho/archive/v1.1-15.5.12-beta.zip 下载后部署到web根目录,然后进行安装即可,其中注 ...

  9. Java实现 HTTP/HTTPS请求绕过证书检测

    java实现 HTTP/HTTPS请求绕过证书检测 一.Java实现免证书访问Https请求 创建证书管理器类 import java.security.cert.CertificateExcepti ...

  10. canal整合springboot实现mysql数据实时同步到redis

    业务场景: 项目里需要频繁的查询mysql导致mysql的压力太大,此时考虑从内存型数据库redis里查询,但是管理平台里会较为频繁的修改增加mysql里的数据 问题来了: 如何才能保证mysql的数 ...