设为首页 加入收藏

TOP

UVA 12034 Race (递推神马的)
2015-07-20 17:30:21 来源: 作者: 【 】 浏览:3
Tags:UVA 12034 Race 神马

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.

    Both first horse 1 first and horse 2 second horse 2 first and horse 1 second

    Input

    Input starts with an integer T ( $ \le$1000), denoting the number of test cases. Each case starts with a line containing an integer n ( 1 $ \le$ n $ \le$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

    3
    1
    2
    3
    

    Sample Output

    Case 1: 1
    Case 2: 3
    Case 3: 13
    
    对,又是递推题目:我们dp[i][j]表示i个马,分j次到达的方法;
    考虑状态转移:dp[i][j]=j*(dp[i-1][j](第i个马和前面的马搭伙到达)+dp[i-1][j-1](第i个马单独算一次))
    #include
        
         
    #include
         
           #include
          
            #include
           
             #include
            
              typedef long long LL; using namespace std; const int MOD=10056; int dp[1100][1100]; int ans[1100]; void init() { memset(dp,0,sizeof(dp)); memset(ans,0,sizeof(ans)); dp[0][0]=1; for(int i=1;i<=1000;i++) { int sum=0; for(int j=1;j<=i;j++) { dp[i][j]+=(dp[i-1][j]+dp[i-1][j-1])%MOD*j%MOD;//小心心爆int sum=(sum%MOD+dp[i][j])%MOD; } ans[i]=sum; } } int main() { init(); int n,t; int cas=1; scanf("%d",&t); while(t--) { scanf("%d",&n); printf("Case %d: %d\n",cas++,ans[n]); } return 0; } 
            
           
          
         
        


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu 3642 Get The Treasury(扫描.. 下一篇leetcode 链表 Partition List

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·每日一道面试题-多线 (2025-12-26 06:20:17)
·java项目中哪些地方 (2025-12-26 06:20:14)
·Java真的是要没落了 (2025-12-26 06:20:12)
·C++ Lambda表达式保 (2025-12-26 05:49:45)
·C++ Lambda表达式的 (2025-12-26 05:49:42)