uva 12034 Race(dp)
来源:互联网 发布:网络虚拟展厅 编辑:程序博客网 时间:2024/06/05 04:01
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 (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
3123
Sample Output
Case 1: 1Case 2: 3Case 3: 13
容易找到dp[i][j]表示i个数种选j个相同的方案数,转移方程详见代码。
#include <cstdio>#include <algorithm>#include <vector>#include <map>#include <queue>#include <iostream>#include <stack>#include <set>#include <cstring>#include <stdlib.h>#include <cmath>using namespace std;typedef long long LL;typedef pair<int, int> P;const int maxn = 1000 + 5;const int mod = 10056;int dp[maxn][maxn];void solve(){ memset(dp, 0, sizeof(dp)); dp[1][0] = dp[1][1] = 1; for(int i = 2;i < maxn;i++){ dp[i][0] = (dp[i-1][0]*i) % mod; dp[i][i] += dp[i][0]; for(int j = 1;j < i-1;j++){ dp[i][j] = ((i-j)*(dp[i-1][j] + dp[i-1][j-1])) % mod; dp[i][i] += dp[i][j]; } dp[i][i-1] = 1; dp[i][i] = (dp[i][i] + dp[i][i-1]) % mod; }}int main(){ int t,kase = 0; solve(); scanf("%d", &t); while(t--){ kase++; int n; scanf("%d", &n); printf("Case %d: %d\n", kase, dp[n][n]); } return 0;}
- uva 12034 Race(dp)
- 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
- 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 11762 Race to 1 dp+概率
- Linux下的shell更改
- SQliteDatabase相关操作的工具类
- mysql 5.6 免安装版配置
- Httpclient使用总结
- 计算一个长方形的面积和周长
- uva 12034 Race(dp)
- WEB服务器、应用程序服务器、HTTP服务器区别
- ORACLE修改语言环境
- c3p0 hikariCp 性能对比
- windows + visual studio 2010 配置SVN(1)
- linux杂谈(十六):ftp的企业应用级配置(三)
- Unicode 和ASCII码
- Null pointer (NULL array pointer is passed) in function cvGetMat, 报这样的错
- Python list 操作