UVA - 12034 (dp)

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

3

1

2

3

Sample Output

Case 1: 1

Case 2: 3

Case 3: 13

题意:
就是问n匹马赛跑比赛结果又多少种可能;

代码:
 

#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
int a[1009][1009];//a[i][j]表示i匹马赛跑一共有j个名次的情况总数。
int main()
{
    for(int i=1;i<=1009;i++)
        {
            a[i][1]=1;
        }
        a[2][2]=2;
        for(int k=3;k<=1003;k++)
        {
            for(int j=2;j<=1003;j++)
            {
                a[k][j]=((a[k-1][j-1]*j)%10056+(a[k-1][j]*j)%10056)%10056;
            }
        }
    int t;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
        int n;
        cin>>n;
        int sum=0;
        for(int i=1;i<=n;i++)
        {
            sum+=a[n][i]%10056;
            sum%=10056;
        }
        printf("Case %d: %d\n",i,sum);
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值