zoukankan      html  css  js  c++  java
  • [CF118D] Caesar's Legions

    [CF118D] Caesar's Legions - dp

    Description

    有 n1 个步兵和 n2 个骑兵,禁止超过 k1 个步兵连续排列,超过 k2 个骑兵连续排列。求方案数。所有的步兵和骑兵都是相同的。

    Solution

    (f[i][j][k][l]) 表示排了 i 个步兵,j 个骑兵,与最后一个人相同的人已经连了 k 个,并且最后一个人是 l

    转移只需要枚举下一个人是骑兵还是步兵即可

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    
    const int mod = 1e8;
    
    int n1, n2, k1, k2, f[105][105][15][3];
    
    signed main()
    {
        ios::sync_with_stdio(false);
    
        cin >> n1 >> n2 >> k1 >> k2;
    
        f[1][0][1][1] = 1;
        f[0][1][1][2] = 1;
    
        for (int i = 0; i <= n1; i++)
        {
            for (int j = 0; j <= n2; j++)
            {
                if (i + j == 0)
                    continue;
                for (int k = 1; k <= max(k1, k2); k++)
                {
                    if (k > k1)
                        f[i][j][k][1] = 0;
                    if (k > k2)
                        f[i][j][k][2] = 0;
                    (f[i + 1][j][k + 1][1] += f[i][j][k][1]) %= mod;
                    (f[i + 1][j][1][1] += f[i][j][k][2]) %= mod;
                    (f[i][j + 1][k + 1][2] += f[i][j][k][2]) %= mod;
                    (f[i][j + 1][1][2] += f[i][j][k][1]) %= mod;
                }
            }
        }
    
        int ans = 0;
        for (int i = 1; i <= k1; i++)
            ans += f[n1][n2][i][1];
        for (int i = 1; i <= k2; i++)
            ans += f[n1][n2][i][2];
    
        ans %= mod;
    
        cout << ans << endl;
    }
    
  • 相关阅读:
    jq 京东跳楼效果
    *Sum of NestedInteger
    **Minimum Window Substring & String类问题模板
    **Word Ladder
    *Longest Increasing Subsequence
    *Kth Largest Element in an Array
    *Permutations II
    *Implement Stack using Queues
    *Paint House II
    *Paint Fence
  • 原文地址:https://www.cnblogs.com/mollnn/p/14426177.html
Copyright © 2011-2022 走看看