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
- horse1 first and horse2 second
- horse2 first and horse1 second
Input
Input starts with an integer T (


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匹马,每次可以乘至少一匹,问有多少种情况。(马与马不同)。
思路:递推,num[i][j]表示i匹马,一共乘j次,num[i][j]=(num[i-1][j]*j+j*num[i-1][j-1])%mod;前一个的意思是i-1匹马乘j次后,第i匹马可以放在任意次去乘,后一个的意思是第i匹马被单独乘,可以有j种单独的方式。
AC代码如下:
#include<cstdio>
#include<cstring>
using namespace std;
int num[1100][1100],mod=10056,ans[1100];
int main()
{ int i,j,k,n,t;
num[1][1]=1;
for(i=2;i<=1000;i++)
for(j=1;j<=i;j++)
num[i][j]=(num[i-1][j]*j+j*num[i-1][j-1])%mod;
for(i=1;i<=1000;i++)
for(j=1;j<=i;j++)
ans[i]=(ans[i]+num[i][j])%mod;
scanf("%d",&t);
for(i=1;i<=t;i++)
{ scanf("%d",&n);
printf("Case %d: %d\n",i,ans[n]);
}
}