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 ( 1n1000).

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

  1. 3
  2. 1
  3. 2
  4. 3

Sample Output

  1. Case 1: 1
  2. Case 2: 3
  3. Case 3: 13
  1. 对,又是递推题目:我们dp[i][j]表示i个马,分j次到达的方法;
  1. 考虑状态转移:dp[i][j]=j*(dp[i-1][j](第i个马和前面的马搭伙到达)+dp[i-1][j-1](第i个马单独算一次))
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<limits.h>
  6. typedef long long LL;
  7. using namespace std;
  8. const int MOD=10056;
  9. int dp[1100][1100];
  10. int ans[1100];
  11. void init()
  12. {
  13.     memset(dp,0,sizeof(dp));
  14.     memset(ans,0,sizeof(ans));
  15.     dp[0][0]=1;
  16.     for(int i=1;i<=1000;i++)
  17.     {
  18.         int sum=0;
  19.         for(int j=1;j<=i;j++)
  20.         {
  21.             dp[i][j]+=(dp[i-1][j]+dp[i-1][j-1])%MOD*j%MOD;//小心心爆int
  22.             sum=(sum%MOD+dp[i][j])%MOD;
  23.         }
  24.         ans[i]=sum;
  25.     }
  26. }
  27. int main()
  28. {
  29.     init();
  30.     int n,t;
  31.     int cas=1;
  32.     scanf("%d",&t);
  33.     while(t--)
  34.     {
  35.         scanf("%d",&n);
  36.         printf("Case %d: %d\n",cas++,ans[n]);
  37.     }
  38.     return 0;
  39. }
  40.  

UVA 12034 Race (递推神马的)的更多相关文章

  1. UVa 12034 Race 递推?

    一开始是想排列组合做的,排列组合感觉确实可以推出公式,但是复杂度嘛.. dp[i][j]表示有i只马,j个名次的方法数,显然j<=i,然后递推公式就很好写了,一只马新加进来要么与任意一个名次的马 ...

  2. UVa 12034 - Race(递推 + 杨辉三角)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. UVa 12034 Race (递推+组合数学)

    题意:A,B两个人比赛,名次有三种情况(并列第一,AB,BA).输入n,求n个人比赛时最后名次的可能数. 析:本来以为是数学题,排列组合,后来怎么想也不对.原来这是一个递推... 设n个人时答案为f( ...

  4. UVA 12034 Race(递推)

    递推,f[i = i个名次][j = 共有j个人] = 方案数. 对于新加入的第j个人,如果并列之前的某个名次,那么i不变,有i个可供并列的名次选择,这部分是f[i][j-1]*i, 如果增加了一个名 ...

  5. UVa 10520【递推 搜索】

    UVa 10520 哇!简直恶心的递推,生推了半天..感觉题不难,但是恶心,不推出来又难受..一不小心还A了[]~( ̄▽ ̄)~*,AC的猝不及防... 先递推求出f[i][1](1<=i< ...

  6. Uva 10446【递推,dp】

    UVa 10446 求(n,bcak)递归次数.自己推出来了一个式子: 其实就是这个式子,但是不知道该怎么写,怕递归写法超时.其实直接递推就好,边界条件易得C(0,back)=1.C(1,back)= ...

  7. UVa 10943 (数学 递推) How do you add?

    将K个不超过N的非负整数加起来,使它们的和为N,一共有多少种方法. 设d(i, j)表示j个不超过i的非负整数之和为i的方法数. d(i, j) = sum{ d(k, j-1) | 0 ≤ k ≤ ...

  8. UVa 557 (概率 递推) Burger

    题意: 有两种汉堡给2n个孩子吃,每个孩子在吃之前要抛硬币决定吃哪一种汉堡.如果只剩一种汉堡,就不用抛硬币了. 求最后两个孩子吃到同一种汉堡的概率. 分析: 可以从反面思考,求最后两个孩子吃到不同汉堡 ...

  9. UVa 1645 Count (递推,数论)

    题意:给定一棵 n 个结点的有根树,使得每个深度中所有结点的子结点数相同.求多棵这样的树. 析:首先这棵树是有根的,那么肯定有一个根结点,然后剩下的再看能不能再分成深度相同的子树,也就是说是不是它的约 ...

随机推荐

  1. 百度编辑器同一id重复调用不能生效的办法

    在使用js 调用表单组件模板的时候,表单内有一个编辑框 第一次调出的时候,百度编辑器正常显示,关闭后,再打开,百度编辑器不能显示 原因:第一次使用的时候, UE.getEditor('node_con ...

  2. 一个故事讲清NIO

    假设某银行只有10个职员.该银行的业务流程分为以下4个步骤: 1) 顾客填申请表(5分钟): 2) 职员审核(1分钟): 3) 职员叫保安去金库取钱(3分钟): 4) 职员打印票据,并将钱和票据返回给 ...

  3. RTP 时间戳的处理

    RTP 时间戳的处理   在RTP传输音频数据时,一般选定逻辑时间戳速率与采样速率相同, 但是在传输视频数据时,必须使时间戳速率大于每帧的一个滴答(这样才能使图像回放更为平滑--<用TCP/IP ...

  4. [Unity3D]Unity3D游戏开发之Lua与游戏的不解之缘终结篇:UniLua热更新全然解读

    ---------------------------------------------------------------------------------------------------- ...

  5. 算法笔记_101:蓝桥杯练习 算法提高 身份证号码升级(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 从1999年10月1日开始,公民身份证号码由15位数字增至18位.(18位身份证号码简介).升级方法为: 1.把15位身份证号码中的年份由 ...

  6. 在进程中执行新代码 execl、execle、execlp、execv、execve和execvp函数

    摘要:本文主要讲述怎样在进程中执行新代码,以及exec系列函数的基本用法. 在进程中执行新代码 用函数fork创建子进程后,假设希望在当前子进程中运行新的程序,能够调用exec函数运行还有一个程序.当 ...

  7. LeetCode-1:Two Sum

    [Problem:1-Two Sum] Given an array of integers, return indices of the two numbers such that they add ...

  8. mysql中的时间类型datetime,date,time,year,timestamp小知识点

    1.datetime,date,time,year四个类型的值,可以手动输入,也可以调用函数获得值 ① 手动输入,格式如下: datetime "2016-6-22 14:09:30&quo ...

  9. js检测回车符

    在说检测回车符之前,需要了解keydown和keypress的区别 比如你可以将检测事件绑定在input上,如下所示: <input name="remark" id=&qu ...

  10. POI操作Excel导入和导出

    Apache的POI组件是Java操作Microsoft Office办公套件的强大API,当中对Word,Excel和PowperPoint都有支持,当然使用较多的还是Excel.由于Word和Po ...