• Educational Codeforces Round 46 (Rated for Div. 2) D. Yet Another Problem On a Subsequence


    这个题是dp, dp[i]代表以i开始的符合要求的字符串数
    j是我们列举出的i之后一个字符串的开始地址,这里的C是组合数
    dp[i] += C(j - i - 1, A[i]] )* dp[j];

    #include <algorithm>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <map>
    #include <queue>
    #include <set>
    #include <stack>
    #include <vector>
    const int N = 1e3 + 5;
    typedef long long ll;
    using namespace std;
    const int MOD = 998244353;
    int A[N];
    ll dp[N];
    ll C[N][N];
    
    
    int main() {
        int n;
        C[0][0] = 1;
        for(int i = 1; i < N; ++i) {
            C[i][0] = 1; C[i][i] = 1;
            for(int j = 1; j <= i/2; ++j) {
                C[i][j] = C[i][i-j] = (C[i-1][j-1] + C[i-1][j]) % MOD;
            }
        }
    
        while(~scanf("%d", &n)) {
            for(int i = 1; i <= n; ++i) {
                scanf("%d", &A[i]);
            }
            memset(dp, 0, sizeof(dp));
            dp[n + 1] = 1;
            for(int i = n; i >= 1; --i) {
                int edpos = i + A[i] + 1;
    
                if(A[i] > 0 && edpos <= n+1) {
                    for(int j = edpos; j <= n+1; ++j) {
                    //    printf("%d %d
    ", i, j);
                        dp[i] = (dp[i] + C[j - i - 1][A[i]] * dp[j] % MOD ) % MOD;
                    }
                } 
           //     printf("hh %d %d
    ", i, dp[i]);
            }
            ll ans = 0;
            for(int i = 1; i <= n; ++i) {
                ans = (ans + dp[i]) % MOD;
            }
            printf("%lld
    ", ans);
        }
        return 0;
    }
    
  • 相关阅读:
    hdu 4948 Kingdom(推论)
    codeforces 407 div1 A题(Functions again)
    Atcoder regular Contest 073(C
    Atcoder regular Contest 073(D
    Nginx阅读笔记(二)之location的用法
    Nginx阅读笔记
    django virtualenv
    Supervisor
    捕捉攻击者
    django user模块改写
  • 原文地址:https://www.cnblogs.com/Basasuya/p/9245450.html
Copyright © 2020-2023  润新知