solution
两 个 操 作 : 两个操作: 两个操作:
j = − j = > t e m p + j = t e m p − j j = -j=>temp+j=temp-j j=−j=>temp+j=temp−j
j = j + a [ i ] = > t e m p + j = t e m p + j + a [ i ] j = j + a[i]=>temp+j=temp+j+a[i] j=j+a[i]=>temp+j=temp+j+a[i]
d p [ i ] [ 2 ∗ t e m p − j ] + = d p [ i − 1 ] [ j ] dp[i][2*temp-j]+=dp[i-1][j] dp[i][2∗temp−j]+=dp[i−1][j]
d p [ i ] [ j − a [ i ] ] + = d p [ i − 1 ] [ j ] dp[i][j-a[i]]+=dp[i-1][j] dp[i][j−a[i]]+=dp[i−1][j]
code
/*SiberianSquirrel*//*CuteKiloFish*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ill = __int128;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = ll(1e8 + 7);
const ll INF = ll(1e18 + 10);
const int N = int(1e5 + 10);
const int M = int(300 * 2 * 666 + 10);
inline int rnd(){static int seed=2333;return seed=(((seed*666666ll+20050818)%998244353)^1000000007)%1004535809;}
template <class T> void read(T &x) {
static char ch;static bool neg;
for(ch=neg=0;ch<'0' || '9'<ch;neg|=ch=='-',ch=getchar());
for(x=0;'0'<=ch && ch<='9';(x*=10)+=ch-'0',ch=getchar());
x=neg?-x:x;
}
ll add(ll a, ll b) {
return (a + b) % MOD;
}
ll sub(ll a, ll b) {
return (a - b + MOD) % MOD;
}
ll mul(ll a, ll b) {
a %= MOD; b %= MOD;
return a * b % MOD;
}
//VAR
ll dp[2][M];
//FUNCTION
//WORK
void solve() {
int n; cin >> n;
vector<int> a(n + 1);
for(int i = 1; i <= n; ++ i) cin >> a[i];
ll temp = 300 * 666;
memset(dp, 0, sizeof dp);
int pos = 0;
dp[pos][temp] = 1;
for(int i = 1; i <= n; ++ i) {
pos = 1 - pos;
for(int j = 0; j < M; ++ j ) dp[pos][j] = 0;
for(int j = 0; j < M; ++ j) {
if(dp[!pos][j]) {
dp[pos][2 * temp - j] = add(dp[pos][2 * temp - j], dp[!pos][j]);
dp[pos][j + a[i]] = add(dp[pos][j + a[i]], dp[!pos][j]);
}
}
dp[pos][temp + 666] = 0;
}
cout << dp[pos][temp - 666] << endl;
}
//MAIN
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef ACM_LOCAL
freopen("input", "r", stdin);
// freopen("output", "w", stdout);
signed test_index_for_debug = 1;
char acm_local_for_debug = 0;
do {
if (acm_local_for_debug == '$') exit(0);
if (test_index_for_debug > 20)
throw runtime_error("Check the stdin!!!");
auto start_clock_for_debug = clock();
solve();
auto end_clock_for_debug = clock();
cout << "Test " << test_index_for_debug << " successful" << endl;
cerr << "Test " << test_index_for_debug++ << " Run Time: "
<< double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl;
cout << "--------------------------------------------------" << endl;
} while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug));
#else
solve();
#endif
return 0;
}