uva 12034——Race
来源:互联网 发布:骚男的淘宝店网址 编辑:程序博客网 时间:2024/06/05 16:36
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 monthsin this way. But everything has an end. A holy person, Munsiji came into theirlife. Munsiji took them to derby (horse racing). Munsiji enjoyed the race, butas usual Disky and Sooma did their as usual task instead of passing someromantic moments. They were thinking- in how many ways a race can finish! Whoknows, maybe this is their romance!
In a race thereare n horses. You have to output the number of ways the racecan finish. Note that, more than on
- Both first
- horse1 first and horse2 second
- horse2 first and horse1 second
Input
Input starts with an integer T (1000), denoting the number of test cases. Each casestarts with a line containing an integer n ( 1n1000).
Output
For each case, print the case number and the number ofways the race can finish. The result can be very large, print the result modulo10056.
Sample Input
3
1
2
3
Sample Output
Case 1: 1
Case 2: 3
Case 3: 13
题意:给定n匹马,要求出可能的排名情况(可能并列)
思路:在刘汝佳书紫书《入门经典第二版》上(具体322页),假设答案为f[n],假设有i个第一,则有c(n,i)中可能,接下来f[n-i]种情况,所以,f[n]=c[n,i]*f[n-i](i为1到n)
co
#include <iostream>
#include <cstdio>
using namespace std;
const int N=1005;
const int mod=10056;
int f[N],c[N][N];
void init()
{
int i,j;
c[1][0]=c[1][1]=1;
for (i=2;i<N;i++)
{
c[i][0]=1;
for (j=1;j<=i/2;j++)
c[i][j]=c[i][i-j]=(c[i-1][j-1]+c[i-1][j])%mod;
}
//f[1]=1;
for (i=1;i<N;i++)
{
f[i]=1;
for (j=1;j<i;j++)
{
f[i]+=c[i][j]*f[i-j];
f[i]%=mod;
}
}
}
int main()
{
int t,n;
init();
while (cin>>t)
{
for(int ca=1;ca<=t;ca++)
{
cin>>n;
printf("Case %d: %d\n",ca,f[n]);
}
}
}
- uva 12034——Race
- UVa 12034 - Race
- UVA - 12034 Race
- UVA 12034 Race
- UVA 12034 Race
- UVA 12034-Race
- uva 12034 Race
- UVA 12034(p332)----Race
- uva 12034 Race
- UVA 12034 Race
- UVA 12034 Race
- UVa 12034 Race
- UVa 12034 Race
- UVA 12034 Race
- UVA 12034 Race
- uva 12034 Race(dp)
- UVA 12034 - Race(递推)
- uva 12034 - Race(dp计数)
- UVA10843——Anne\'s game
- Java 多线程 网络路由
- UVA - 10497 Sweet Child Makes Trouble
- uva 10883——Supermean
- UVA 10079 - Pizza Cutting
- uva 12034——Race
- 卡特兰数的性质及其应用扩展
- uva 10312——Expression Bracketing
- uva 10692——Huge Mods
- uva 10710——Chinese Shuffle
- 中国剩余定理即孙子定理的五种解法
- uva 11490 ——Just Another Problem
- uva 11728——Alternate Task
- uva 10110——Light, more light