用表示第位置保留且当前公差为d的方案数
这里的+1代表直接由j转移而来,由于对于i和j来讲,公差已经固定,即
对于负的公差,整体加个v即可
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 1e3 + 10, D = 2e4 + 10, v = 2e4, P = 998244353;
int f[N][2 * D], n, a[N], ans = 0;
int es(int x){
return x - v;
}
int cp(int x){
return x + v;
}
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i ++)
scanf("%d", &a[i]);
for(int i = 1; i <= n; i ++){
for(int j = 1; j < i; j ++){
f[i][cp(a[i] - a[j])] += f[j][cp(a[i] - a[j])] + 1;
f[i][cp(a[i] - a[j])] %= P;
ans = (ans + f[j][cp(a[i] - a[j])] + 1) % P;
}
}
printf("%d", ans + n);
return 0;
}