Codeforces-118D. Caesar's Legions(lazy dynamics)

Posted xFANx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces-118D. Caesar's Legions(lazy dynamics)相关的知识,希望对你有一定的参考价值。

传送门

 

把n1个步兵和n2个骑兵派成一列,已知连续的步兵不超过k1个,连续的骑兵不超过k2个,求总可能排列情况数

 

定义dp[i][j][2],指使用i个步兵,j个骑兵的排列。0代表排头为步兵,1代表排头为骑兵

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define INF 0x3f3f3f3f
#define MOD 100000000
using namespace std;
typedef long long LL;

int N1, N2, K1, K2;
const int maxn = 110;
int dp[maxn][maxn][2];

int main() {
    scanf("%d%d%d%d", &N1, &N2, &K1, &K2);
    for (int i = 0; i <= K1; i++) dp[i][0][0] = 1;
    for (int i = 0; i <= K2; i++) dp[0][i][1] = 1;
    for (int i = 1; i <= N1; i++) {
        for (int j = 1; j <= N2; j++) {
            for (int k = 1; k <= min(i, K1); k++) {
                dp[i][j][0] = (dp[i][j][0] + dp[i - k][j][1]) % MOD;
            }
            for (int k = 1; k <= min(j, K2); k++) {
                dp[i][j][1] = (dp[i][j][1] + dp[i][j - k][0]) % MOD;
            }
        }
    }
    int ans = (dp[N1][N2][0] + dp[N1][N2][1]) % MOD;
    printf("%d\n", ans);

    return 0;
}

 

以上是关于Codeforces-118D. Caesar's Legions(lazy dynamics)的主要内容,如果未能解决你的问题,请参考以下文章

CodeForces - 118A String Task

Codeforces 118A String Task

codeforces118d

Caesar Cipher

Codeforces gym102222 C. Caesar Cipher 签到

D. Caesar's Legions 背包Dp 递推DP