Race UVA - 12034
2017-10-10 17:49
441 查看
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
line containing an integer n (1 ≤ n ≤ 1000).
very large, print the result modulo 10056.
1
2
3
Case 2: 3
Case 3: 13
可以有多匹马占用同一个名次,问n匹马有几种比赛结果。
状态转移方程是s[i][j]=(s[i-1][j]*j+s[i-1][j-1]*j),指i匹马最后有j个名次的情况,可以由i-1匹有j个名次的情况中,某个名次多加一匹马得到,也可以由i-1匹有j-1个名次的情况中,多加一匹马单独占有一个名次得到,即两种情况之和。
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 aline 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 bevery large, print the result modulo 10056.
Sample Input
31
2
3
Sample Output
Case 1: 1Case 2: 3
Case 3: 13
可以有多匹马占用同一个名次,问n匹马有几种比赛结果。
状态转移方程是s[i][j]=(s[i-1][j]*j+s[i-1][j-1]*j),指i匹马最后有j个名次的情况,可以由i-1匹有j个名次的情况中,某个名次多加一匹马得到,也可以由i-1匹有j-1个名次的情况中,多加一匹马单独占有一个名次得到,即两种情况之和。
#include <iostream> #include <string.h> using namespace std; int s[1005][1005]; int ss[1005]; int main() { int i,j,T,n,k; memset(s,0,sizeof(s)); memset(ss,0,sizeof(ss)); s[1][1]=1; ss[1]=1; for(i=2;i<=1000;i++){ for(j=1;j<=i;j++){ s[i][j]=(s[i-1][j]*j+s[i-1][j-1]*j)%10056; ss[i]+=s[i][j]; ss[i]%=10056; } } cin>>T; k=1; while(k<=T){ cin>>n; cout<<"Case "<<k<<": "; cout<<ss <<endl; k++; } return 0; }
相关文章推荐
- (UVA - 12034)Race(组合数,dp)
- uva 12034 Race
- UVa 12034 Race
- UVa 12034 (递推) Race
- UVA 12034 - Race(递推)
- uva 12034 Race
- UVa 12034 - Race(组合+递推)
- 【UVA】12034-Race(递推,组合数打表)
- Race - UVa 12034 递推
- uva 12034 Race(递推+组合数)
- UVA 12034 Race
- UVA 12034 Race 赛马名次
- UVA 12034 Race
- UVA 12034 Race
- UVA 12034 Race
- UVA 12034 Race
- UVa12034 Race 递推
- CSU-ACM2017暑期训练3-递推与递归 H - Race UVA - 12034
- UVA 12034-Race
- UVa 12034 Race (递推+组合数学)