uva 12034 Race(dp)
2014-05-06 10:43
309 查看
Race |
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 ( 1
n
1000).
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
容易找到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 ); } return 0; }
相关文章推荐
- (UVA - 12034)Race(组合数,dp)
- UVA 12034 Race ——dp
- uva 12034 - Race(dp计数)
- UVA 12034 Race(递推)
- Race UVA - 12034
- UVA 12034 Race 赛马名次
- UVA 12034 Race
- UVA 12034 Race
- UVA 12034(p332)----Race
- Race - UVa 12034 递推
- UVa 11762 (期望 DP) Race to 1
- UVA 12034 Race
- UVa 12034 Race
- uva 12034 Race
- CSU-ACM2017暑期训练3-递推与递归 H - Race UVA - 12034
- UVa 12034 Race
- uva 12034 Race(递推+组合数)
- UVa 12034 Race (递推+组合数学)
- UVa12034 Race 递推
- UVA - 12034 Race