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

Bryce1010模板

http://codeforces.com/problemset/problem/1000/D
题意:
要求一个序列有多少个子好序列。
思路:组合数+动态规划

#include
using namespace std;
#define ll long long
const ll MAXN=1000+50;
const ll mod=998244353;
ll C[MAXN][MAXN];
ll a[MAXN],dp[MAXN];

//先把组合数的公式计算出来
void init()
{
    C[0][0]=C[1][0]=C[1][1]=1;
    for(ll i=2;i<=1005;i++)
    {
        C[i][0]=C[i][i]=1;
        for(ll j=1;j1][j-1]+C[i-1][j])%mod;
        }
    }
}
int main()
{
    init();
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    ll ans=0;
    //dp[n+1]=1;
    //dp[i]=dp[i]+C[j-i+1][a[i]]*dp[j]
    for(ll i=n; i>0; i--)
    {
        if(a[i]>0)
        {
            for(ll j=i+a[i]; j<=n; j++)
            {
                dp[i]=dp[i]+C[j-i-1][a[i]-1]*(dp[j+1]+1)%mod;
                dp[i]%=mod;
            }
        }
        dp[i]+=dp[i+1]%mod;
        dp[i]%=mod;
        //ans=(ans+dp[i])%mod;
    }
    cout<1]<return 0;
}

你可能感兴趣的:(Educational Codeforces Round 46 (Rated for Div. 2) D. Yet Another Problem On a Subsequence)