题目大意
给定序列 h1,dots,hn。统计所有长度至少为 1 的等差子序列的个数(对 998244353 取模)。
AC代码
具体思路与该题解一致
https://www.luogu.com.cn/article/hrn3rj07
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| #include <iostream> #include <vector> using namespace std; const int mod=998244353,N=1010,MAXR=4e4+10,R=4e4; int n,h[N],dp[N][MAXR*2],ans;
int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n; for(int i=1;i<=n;i++) { cin>>h[i]; } for(int i=1;i<=n;i++) { ans++; for(int j=i-1;j>=1;j--) { dp[i][h[i]-h[j]+R]+=dp[j][h[i]-h[j]+R]+1; dp[i][h[i]-h[j]+R]%=mod; ans+=dp[j][h[i]-h[j]+R]+1; ans%=mod; } } ans%=mod; cout<<ans<<endl; return 0; }
|
心路历程(WA,TLE,MLE……)