http://codeforces.com/contest/1000/problem/D
题意:定义好数组是【a0,a1,,,an】且n==a0;或者一个数组能正好分成好数组,再就是通过样例可以看出不必选择连续的
思路:一开始我理解的是推得排列组合公式+递推。。。但是因为要取余,要用到逆元,比赛的时候时间也不太够,就没有做出来,,,赛后了解了一下除法取余的做法。。然后看了一下别人的代码,竟然发现是个dp,,,,比自己的做法好多了。。。
代码:
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
int t[1005],n,x;
int main()
{
cin>>n;
t[0]=1;
for (int i=0;i<n;i++)
{
int a;
cin>>a;
x=t[0];
for (int j=0;j<=n;j++) t[j]=(t[j]+t[j+1])%mod;
if (a>0 && a<=n) t[a]=(t[a]+x)%mod;
}
cout<<(t[0]-1+mod)%mod<<endl;
return 0;
}