#pragma GCC optimize ("Ofast") #define _USE_MATH_DEFINES #include <bits/stdc++.h> #define FOR(i, a, b) for (int i=(a); i<(b); i++) #define FORD(i, a, b) for (int i=(a); i>(b); i--) #define PPC(x) __builtin_popcount(x) #define MSB(x) (63 - __builtin_clzll(x)) #define SZ(x) ((int)(x).size()) #define HASK(S, x) (S.find(x) != S.end()) #define pb push_back #define ALL(x) (x).begin(), (x).end() #define ithBit(m, i) ((m) >> (i) & 1) #define ft first #define sd second #define kw(a) ((a) * (a)) #ifdef DEBUG #include "debug.h" #else #define dbg(...) 0 #endif using namespace std; const int maxN = 5003, mod = 1000000007; int T[maxN]; long long dp[maxN][maxN]; void solve() { int n; scanf ("%d", &n); FOR(i, 1, n+1) scanf ("%d", T+i); sort(T, T+n+1); dp[0][0] = 1ll; FOR(i, 1, n+1) FOR(s, 0, maxN) { int q = max(T[i]-1, s-T[i]); dp[i][s] = dp[i-1][q]; dp[i][s] = (dp[i][s] + dp[i-1][s]) % mod; } printf("%lld\n", dp[n][1]); } int main() { int t = 1; //scanf ("%d", &t); FOR(tid, 1, t+1) { //printf("Case #%d: ", tid); solve(); } return 0; }
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 | #pragma GCC optimize ("Ofast") #define _USE_MATH_DEFINES #include <bits/stdc++.h> #define FOR(i, a, b) for (int i=(a); i<(b); i++) #define FORD(i, a, b) for (int i=(a); i>(b); i--) #define PPC(x) __builtin_popcount(x) #define MSB(x) (63 - __builtin_clzll(x)) #define SZ(x) ((int)(x).size()) #define HASK(S, x) (S.find(x) != S.end()) #define pb push_back #define ALL(x) (x).begin(), (x).end() #define ithBit(m, i) ((m) >> (i) & 1) #define ft first #define sd second #define kw(a) ((a) * (a)) #ifdef DEBUG #include "debug.h" #else #define dbg(...) 0 #endif using namespace std; const int maxN = 5003, mod = 1000000007; int T[maxN]; long long dp[maxN][maxN]; void solve() { int n; scanf ("%d", &n); FOR(i, 1, n+1) scanf ("%d", T+i); sort(T, T+n+1); dp[0][0] = 1ll; FOR(i, 1, n+1) FOR(s, 0, maxN) { int q = max(T[i]-1, s-T[i]); dp[i][s] = dp[i-1][q]; dp[i][s] = (dp[i][s] + dp[i-1][s]) % mod; } printf("%lld\n", dp[n][1]); } int main() { int t = 1; //scanf ("%d", &t); FOR(tid, 1, t+1) { //printf("Case #%d: ", tid); solve(); } return 0; } |