CodeForces 118D Caesar's Legions
2015-02-19 17:22
330 查看
Description
Gaius Julius Caesar, a famous general, loved to line up his soldiers. Overall the army had n1 footmen and n2 horsemen.
Caesar thought that an arrangement is not beautiful if somewhere in the line there are strictly more that k1 footmen standing
successively one after another, or there are strictly more than k2 horsemen standing successively one after another. Find the number of beautiful arrangements
of the soldiers.
Note that all n1 + n2 warriors should be present at each arrangement. All footmen are considered indistinguishable among
themselves. Similarly, all horsemen are considered indistinguishable among themselves.
Input
The only line contains four space-separated integers n1, n2, k1, k2 (1 ≤ n1, n2 ≤ 100, 1 ≤ k1, k2 ≤ 10)
which represent how many footmen and horsemen there are and the largest acceptable number of footmen and horsemen standing in succession, correspondingly.
Output
Print the number of beautiful arrangements of the army modulo 100000000(108). That is, print the number of such
ways to line up the soldiers, that no more than k1 footmen stand successively, and no more than k2 horsemen
stand successively.
Sample Input
Input
Output
Input
Output
Input
Output
Hint
Let's mark a footman as 1, and a horseman as 2.
In the first sample the only beautiful line-up is: 121
In the second sample 5 beautiful line-ups exist: 12122, 12212, 21212, 21221, 22121
动态规划还得好好研究研究
Gaius Julius Caesar, a famous general, loved to line up his soldiers. Overall the army had n1 footmen and n2 horsemen.
Caesar thought that an arrangement is not beautiful if somewhere in the line there are strictly more that k1 footmen standing
successively one after another, or there are strictly more than k2 horsemen standing successively one after another. Find the number of beautiful arrangements
of the soldiers.
Note that all n1 + n2 warriors should be present at each arrangement. All footmen are considered indistinguishable among
themselves. Similarly, all horsemen are considered indistinguishable among themselves.
Input
The only line contains four space-separated integers n1, n2, k1, k2 (1 ≤ n1, n2 ≤ 100, 1 ≤ k1, k2 ≤ 10)
which represent how many footmen and horsemen there are and the largest acceptable number of footmen and horsemen standing in succession, correspondingly.
Output
Print the number of beautiful arrangements of the army modulo 100000000(108). That is, print the number of such
ways to line up the soldiers, that no more than k1 footmen stand successively, and no more than k2 horsemen
stand successively.
Sample Input
Input
2 1 1 10
Output
1
Input
2 3 1 2
Output
5
Input
2 4 1 1
Output
0
Hint
Let's mark a footman as 1, and a horseman as 2.
In the first sample the only beautiful line-up is: 121
In the second sample 5 beautiful line-ups exist: 12122, 12212, 21212, 21221, 22121
动态规划还得好好研究研究
#include<iostream> #include<algorithm> #include<math.h> #include<cstdio> #include<string> #include<string.h> using namespace std; const int maxn = 105; const int base = 100000000; int n, m, k1, k2, i, j, k, f[maxn][maxn][12][2], sum; int main(){ while (~scanf("%d%d%d%d", &n, &m, &k1, &k2)) { memset(f, 0, sizeof(f)); f[1][0][1][0] = 1; f[0][1][1][1] = 1; for (i = 0; i <= n;i++) for (j = 0; j <= m; j++) if (i + j >1) { for (k = 2; k <= k1; k++) if (i) f[i][j][k][0] = f[i - 1][j][k - 1][0]; for (k = 2; k <= k2; k++) if (j) f[i][j][k][1] = f[i][j - 1][k - 1][1]; for (k = 1; k <= k2; k++) if (i) f[i][j][1][0] = (f[i][j][1][0] + f[i - 1][j][k][1]) % base; for (k = 1; k <= k1; k++) if (j) f[i][j][1][1] = (f[i][j - 1][k][0] + f[i][j][1][1]) % base; } for (sum = 0, i = 1; i <= max(k1, k2); i++) sum = (sum + f [m][i][0] + f [m][i][1]) % base; printf("%d\n", sum); } return 0; }
相关文章推荐
- codeforces 118D Caesar's Legions(DP进阶)
- codeforces 118D Caesar's Legions (好题)
- codeforces 118D Caesar's Legions 背包问题
- Codeforces 118D Caesar's Legions (dp)
- [CodeForces 118D] Caesar's Legions (计数DP)
- CF Beta Round #89 (Div. 2) - Caesar's Legions
- Codeforces 433 C. Ryouko's Memory Note
- codeforces 459D - Pashmak and Parmida's problem【离散化+处理+逆序对】
- codeforces 118D D. Caesar's Legions(dp)
- CodeForces 576A - Vasya and Petya's Game
- codeforces 235B - Let's Play Osu!
- codeforces 591 D. Chip 'n Dale Rescue Rangers
- Codeforces 768A Oath of the Night's Watch
- codeforces 235B Let's Play Osu! 概率dp
- 51nod 1536不一样的猜数游戏 O(n)素数筛选法。同Codeforces 576A Vasya and Petya's Game。
- CodeForces-630B. Moore's Law
- Codeforces 118 D. Caesar's Legions (dp)
- CodeForces 6B President's Office
- codeforces 118-D. Caesar's Legions(dp计数)
- codeforces 686B Little Robber Girl's Zoo (sort)