UVA 12034 Race
来源:互联网 发布:淘宝首页在线制作 编辑:程序博客网 时间:2024/06/04 19:12
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.
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 ( 1n1000).
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匹马赛跑,一共有多少结局。
两匹马有三种结局
1. Both first
2. horse1 first and horse2 second
3. horse2 first and horse1 second
#include<stdio.h>
#include<cstring>
int modulo=10056;
int s[1010][1010];
int p[1010];
int main()
{
int t,n;
scanf("%d",&t);
int q=1;
int sum;
n=1000;
memset(s,0,sizeof s);
s[1][1]=1;
for(int i=2;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
s[i][j]+=(s[i-1][j]*j+s[i-1][j-1]*j)%modulo;
}
}
for(int i=1;i<=n;i++)
{
sum=0;
for(int j=1;j<=i;j++)
{
sum=(sum+s[i][j])%modulo;
}
p[i]=sum;
}
while(t--)
{
scanf("%d",&n);
printf("Case %d: %d\n",q++,p[n]);
}
return 0;
}
MOD运算
mod运算,即求余运算,是在整数运算中求一个整数x除以另一个整数y的余数的运算,且不考虑运算的商。
在计算机程序设计中都有MOD运算,它的含义是 取得两个整数相除后结果的余数。
如:7 mod 3 = 1
因为7 除以 3 商2余1,余数1即MOD运算后的结果。
- 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计数)
- Race - UVa 12034 递推
- hdu 1290 切蛋糕
- Nginx实现反向代理(同一服务器下不同端口服务映射到80端口)
- Retrofit结合RxJava1.x使用
- AD导入logo
- TLP280-4 与 TLP281-4区别
- UVA 12034 Race
- 查询及删除重复记录的SQL语句
- 20171103
- 阿里云的OSS对象存储 java
- 三齿轮问题:三个齿轮啮合
- LeetCode 654. Maximum Binary Tree
- 经典排序算法
- bzoj1049 [HAOI2006]数字序列 ( LIS + 区间DP)
- SpringBoot自动配置的实现原理