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 }

最新文章

  1. 用markdown简化书写
  2. centos6 系统优化脚本
  3. What is the difference between parameterized queries and prepared statements?
  4. Google面试题:计算从1到n的正数中1出现的次数
  5. Swift - 37 - 值类型和引用类型的简单理解
  6. 向Dialog中添加一个新的Menu
  7. ajax经典面试题
  8. c/c++ 标准库 map set 大锅炖
  9. jvm理论-字节码指令
  10. spring boot 搭建
  11. [转] 可跨域的单点登录(SSO)实现方案
  12. JAVA和C#检测IP地址段是否交叉和获取地址段IP列表的方法
  13. [记录] Linux Apache隐藏index.php
  14. css左右等高问题
  15. bitnami redmine配置全过程
  16. Android Activity全面解析
  17. python中获取当前路径并添加到系统路径
  18. WPF 窗口句柄获取和设置
  19. Git 提示fatal: remote origin already exists
  20. MongoDB的容量规划及硬件配置

热门文章

  1. accurate, accuse
  2. Java文件操作(求各专业第一名的学生)
  3. Output of C++ Program | Set 6
  4. activiti工作流引擎
  5. spring的核心容器ApplicationContext
  6. 使用matplotlib中的bar函数绘制柱状图
  7. 分布式事务之TCC事务模型
  8. STL模板前言(1)
  9. 象群游牧算法--EHO
  10. Python pyecharts绘制漏斗图