• cf1152D


    #include<bits/stdc++.h>
    #define forn(i, n) for (int i = 0 ; i < int(n) ; i++)
    #define fore(i, s, t) for (int i = s ; i < (int)t ; i++)
    #define fi first
    #define se second
    #define all(x) x.begin(),x.end()
    #define pf2(x,y) printf("%d %d
    ",x,y)
    #define pf(x) printf("%d
    ",x)
    #define each(x) for(auto it:x)  cout<<it<<endl;
    #define pii pair<int,int>
    #define sc(x) scanf("%d",&x)
    using namespace std;
    typedef long long ll;
    const int maxn=1e4+5;
    const int maxm=2e5+5;
    const int inf=1e9;
    const int mod = 1000 * 1000 * 1000 + 7;
    int add(int a, int b) {
        return (a + b >= mod ? a + b - mod : a + b);
    }
    const int max_n = 1001;
    pair<int, bool> dp[2 * max_n][2 * max_n];
    int main() {
    	int n;
       	sc(n);
        n *= 2;
        dp[0][0] = make_pair(0, true);
        for (int len = 1; len <= n; ++len) {
            for (int bal = 0; bal <= n; ++bal) {
                // (len, bal) -> (len - 1, bal + 1)
                // (len, bal) -> (len - 1, bal - 1)
                int sum = 0;
                bool has = false;
                if (bal != 0) {
                    sum = add(sum, dp[len - 1][bal - 1].first);
                    has = has or dp[len - 1][bal - 1].second;
                }
                if (bal + 1 <= len - 1) {
                    sum = add(sum, dp[len - 1][bal + 1].first);
                    has = has or dp[len - 1][bal + 1].second;
                }
                if (has)
                    dp[len][bal] = make_pair(add(sum, 1), false);
                else
                    dp[len][bal] = make_pair(sum, true);
            }
        }
        cout << dp[n][0].first << "
    ";
        return 0;
    }
    

      

  • 相关阅读:
    上下文有关文法
    sqlserver cte 速度慢
    hibernate tools eclipse 安装
    sts java nullpointer exception
    Oracle RAC集群体系结构
    bean scope scoped-proxy
    hibernate persist不能插入到表中
    system.out 汉字乱码
    NoSQL数据库(转)
    在PowerShell中获取本地的RAM信息(容量)
  • 原文地址:https://www.cnblogs.com/033000-/p/12384617.html
Copyright © 2020-2023  润新知