Problem - 1783D - Codeforces
思路: 这是一个计数问题,我们要统计不同数组的个数,可以用dp,让f[i][j]表示只考虑前i个,并且结尾为j的情况,那么转移方程为我们枚举i,与枚举前一个是多少,那么转移方程为
f[i][w[i]-j]+=f[i-1][j],f[i][w[i]+j]+=f[i-1][j],只有在j为0的时候只用转移一次,同时因为有负数,所以我们要同时扩大一个数让多有的数变为正数,最后只需要统计f[n][k],枚举k的所有情况即可
// Problem: D. Different Arrays
// Contest: Codeforces - Educational Codeforces Round 141 (Rated for Div. 2)
// URL: https://codeforces.com/problemset/problem/1783/D
// Memory Limit: 512 MB
// Time Limit: 2000 ms
#include<iostream>
#include<cstring>
#include<string>
#include<sstream>
#include<bitset>
#include<deque>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<set>
#include<cstdlib>
#define fi first
#define se second
#define i128 __int128
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> PII;
typedef pair<int,pair<int,int> > PIII;
const double eps=1e-7;
const int N=5e5+7 ,M=5e5+7, INF=0x3f3f3f3f,mod=1e9+7,mod1=998244353;
const long long int llINF=0x3f3f3f3f3f3f3f3f;
inline ll read() {ll x=0,f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') {x=(ll)x*10+c-'0';c=getchar();} return x*f;}
inline void write(ll x) {if(x < 0) {putchar('-'); x = -x;}if(x >= 10) write(x / 10);putchar(x % 10 + '0');}
inline void write(ll x,char ch) {write(x);putchar(ch);}
void stin() {freopen("in_put.txt","r",stdin);freopen("my_out_put.txt","w",stdout);}
bool cmp0(int a,int b) {return a>b;}
template<typename T> T gcd(T a,T b) {return b==0?a:gcd(b,a%b);}
template<typename T> T lcm(T a,T b) {return a*b/gcd(a,b);}
void hack() {printf("\n----------------------------------\n");}
int T,hackT;
int n,m,k;
int w[N];
ll f[310][310*310+310*310];
void solve() {
n=read();
for(int i=1;i<=n;i++) w[i]=read();
f[2][w[2]+310*310]++;
for(int i=3;i<=n;i++) {
for(int j=(i-1)*-300;j<=(i-1)*300;j++) {
if(!j) {
f[i][w[i]+310*310]=(f[i][w[i]+310*310]+f[i-1][j+310*310])%mod1;
}else {
f[i][w[i]-j+310*310]=(f[i][w[i]-j+310*310]+f[i-1][j+310*310])%mod1;
f[i][w[i]+j+310*310]=(f[i][w[i]+j+310*310]+f[i-1][j+310*310])%mod1;
}
}
}
ll res=0;
for(int i=0;i<310*310+310*310;i++) res=(res+f[n][i])%mod1;
printf("%lld\n",res);
}
int main() {
// init();
// stin();
// scanf("%d",&T);
T=1;
while(T--) hackT++,solve();
return 0;
}