luogu4933 大师 (dp)

记f[i][j]是以i号为结尾的、公差为j的的个数(不包括只有i的情况)

那么就有$f[i][i-i']=\sum{(f[i'][i-i']+1)}$之类的东西

最后再加个n就行啦

而且公差有可能有负的,都加个20000好了

 1 #include<bits/stdc++.h>
 2 #define pa pair<int,int>
 3 #define CLR(a,x) memset(a,x,sizeof(a))
 4 using namespace std;
 5 typedef long long ll;
 6 const int maxn=1010,maxv=40010,P=998244353;
 7 
 8 inline ll rd(){
 9     ll x=0;char c=getchar();int neg=1;
10     while(c<'0'||c>'9'){if(c=='-') neg=-1;c=getchar();}
11     while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
12     return x*neg;
13 }
14 
15 int f[maxn][maxv];
16 int N,h[maxn];
17 
18 int main(){
19     //freopen("","r",stdin);
20     int i,j,k;
21     N=rd();
22     for(i=1;i<=N;i++)
23         h[i]=rd();
24     for(i=2;i<=N;i++){
25         for(j=1;j<=i-1;j++){
26             f[i][h[i]-h[j]+20000]=(f[i][h[i]-h[j]+20000]+f[j][h[i]-h[j]+20000]+1)%P;
27         }
28     }
29     ll ans=N;
30     for(i=1;i<=N;i++){
31         for(j=0;j<=40000;j++){
32             ans=(ans+f[i][j])%P;
33         }
34     }
35     printf("%lld\n",ans);
36     return 0;
37 }

猜你喜欢

转载自www.cnblogs.com/Ressed/p/9833439.html
今日推荐