-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path255D.cpp
81 lines (69 loc) · 1.46 KB
/
255D.cpp
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include <algorithm>
#include <vector>
#define MOD 1000000007
#include <list>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#define ll long long
#define REP(i,a,n) for(i=(int)a;i<n;i++)
#define REPP(i,a,n) for(i=(int)a;i<=n;i++)
#include <cmath>
#define PI pair<int,int>
#include <cstdlib>
#define inf 1000007
#include <ctime>
#define exit return 0
#define N 1<<18
using namespace std;
vector<int>gr[N];
vector<int>pref[N];//k>j
vector<int>suff[N];//all child of i k<j-ze
//number of substrings with sum 0
//dp-state number of valid substrings that ends with i ,sum of j
int dp[1111][31111], h[N], c[N], jam[N], pas, NN, X;
int i, j, k, KK, R;
vector<int>ans;
void add(int x){
if (x > MOD){
x -= MOD;
}
}
const int SUM = 10000;
#define PS system("pause")
int main(){
cin >> NN;
REP(i, 0, NN)cin >> c[i];
//current index with sum of j
dp[0][SUM] = 1;
REP(i, 0, NN){
REPP(j, 0, SUM + SUM){
if (j >= c[i])
dp[i + 1][j] += dp[i][j - c[i]];
if (j + c[i] <= SUM + SUM)
dp[i + 1][j] += dp[i][j + c[i]];
dp[i + 1][j] %= MOD;
}
pas = (pas + dp[i + 1][SUM]) % MOD;
//add(dp[i + 1][SUM]);
dp[i + 1][SUM] += 1;
dp[i + 1][SUM] %= MOD;
//add(dp[i + 1][SUM]);
}
cout << pas;
return 0;
}