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的第十天

    一.今日收获 1.java完全学习手册第二章2.9程序流程控制中的选择结构与顺序结构的例题 2.观看哔哩哔哩上的教学视频 二.今日问题 1.例题的问题不大,需要注意大小写,新的语句记忆不牢 2.哔哩哔 ...

  2. Kafka入门教程(二)

    转自:https://blog.csdn.net/yuan_xw/article/details/79188061 Kafka集群环境安装 相关下载 JDK要求1.8版本以上. JDK安装教程:htt ...

  3. 零基础学习java------38---------spring中关于通知类型的补充,springmvc,springmvc入门程序,访问保护资源,参数的绑定(简单数据类型,POJO,包装类),返回数据类型,三大组件,注解

    一. 通知类型 spring aop通知(advice)分成五类: (1)前置通知[Before advice]:在连接点前面执行,前置通知不会影响连接点的执行,除非此处抛出异常. (2)正常返回通知 ...

  4. 【1】Embarrassingly Parallel(易并行计算问题)

    1.什么是Embarrassingly Parallel(易并行计算问题) 易并行计算问题:A computation that can be divided into a number of  co ...

  5. android studio 生成aar和引用aar

    以android studio 2.0正式版为例 1.aar包是Android studio下打包android工程中src.res.lib后生成的aar文件,aar包导入其他android stud ...

  6. Lock锁的使用

    在Java多线程中,可以使用synchronized关键字实现线程之间的同步互斥,在jdk1.5后新增的ReentrantLock类同样可达到此效果,且在使用上比synchronized更加灵活. 观 ...

  7. Hadoop生态圈学习-1(理论基础)

    一.大数据技术产生的背景 1. 计算机和信息技术(尤其是移动互联网)的迅猛发展和普及,行业应用系统的规模迅速扩大(用户数量和应用场景,比如facebook.淘宝.微信.银联.12306等),行业应用所 ...

  8. 【Service】【MiddleWare】【Message】rabbitMQ

    1. 概念: 1.1. 消息型中间件:遵循AMQP协议(高级消息队列协议)AMQP 0-9-1 AMQP 1.0 1.2. 路由模型: direct topic fan-out headers 1.3 ...

  9. 使用jquery刷新页面以及javascript的一些基本函数

    如何使用jquery刷新当前页面 下面介绍全页面刷新方法:有时候可能会用到 1.window.location.reload()刷新当前页面. 2.parent.location.reload()刷新 ...

  10. MySQL索引及性能优化分析

    一.SQL性能下降的原因 查询语句问题,各种连接.子查询 索引失效(单值索引.复合索引) 服务器调优及各个参数设置(缓冲.线程池等) 二.索引 排好序的快速查找数据结构 1. 索引分类 单值索引 一个 ...