标签:
Description
|
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.
3 1 2 3
Case 1: 1 Case 2: 3 Case 3: 13
Source
/* *********************************************** Author :CKboss Created Time :2015年01月07日 星期三 21时21分14秒 File Name :UVA12034.cpp ************************************************ */ #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <cmath> #include <cstdlib> #include <vector> #include <queue> #include <set> #include <map> using namespace std; const int mod = 10056; int n; int C[2000][2000]; int f[2000]; void init() { for(int i=0;i<1100;i++) C[i][0]=C[i][i]=1; for(int i=2;i<1100;i++) for(int j=1;j<i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod; f[0]=1; f[1]=1; f[2]=3; f[3]=13; for(int i=4;i<=1000;i++) { int ans=0; for(int j=1;j<=i;j++) { ans=(ans+C[i][j]*f[i-j])%mod; } f[i]=ans; } } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); init(); int T_T,cas=1; scanf("%d",&T_T); while(T_T--) { scanf("%d",&n); printf("Case %d: %d\n",cas++,f[n]); } return 0; }
标签:
原文地址:http://blog.csdn.net/ck_boss/article/details/42507123