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

Posted basasuya

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}


以上是关于Educational Codeforces Round 46 (Rated for Div. 2) D. Yet Another Problem On a Subsequence的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 7 A

Educational Codeforces Round 7

Educational Codeforces Round 90

Educational Codeforces Round 33

Codeforces Educational Codeforces Round 54 题解

Educational Codeforces Round 27