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
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匹马比赛,名次可以并列,问有多少种这样的情况?
设有i个人第一,那么剩余n-i个人排剩余名次,即相当于(n-i)个人的排列数,
由此,我们可以用递推来解决这个问题,其中,递推式为: f[n]=c(i,n)*f[n-i]
代码如下:
#include <iostream>
#include <cstdio>
#include <map>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include<cassert>
using namespace std;
#define maxn 1005
#define mod 10056
int c[maxn][maxn],f[maxn];
void p()
{
c[1][1]=c[0][1]=1;
for(int i=2;i<maxn;i++){
for(int j=0;j<=i;j++){
if(j==0||j==i) c[j][i]=1;
else{
c[j][i]=(c[j][i-1]+c[j-1][i-1])%mod;
}
}
}
memset(f,0,sizeof(f));
f[0]=1;
for(int i=1;i<maxn;i++){
for(int j=0;j<=i;j++){
f[i]+=c[j][i]*f[i-j];
f[i]%=mod;
}
}
}
int main() {
int t,n,ca=1;
p();
scanf("%d",&t);
while(t--){
scanf("%d",&n);
printf("Case %d: %d\n",ca++,f[n]);
}
return 0;
}