#include <cstdio> #include <algorithm> using namespace std; const int MOD = 1000000007; int a[5001]; int tab[10001]; int tmp[10001]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", a + i); } sort(a, a + n); tab[0] = 1; tmp[0] = 1; int T = 1; int suf = 0; for (int i = 0; i < n; i++) { int c = 0; //int k = T - 1; int first = -1; bool ok = true; for (int j = 10000; j >= 0; j--) { if (tmp[j]) { if (first == -1) { first = 1; if (j < a[i] - 1) { ok = false; break; } } } } if (!ok) break; suf *= 2; suf %= MOD; for (int j = 10000; j >= 0; j--) { if (!tmp[j]) continue; if (j < a[i] - 1) break; int t = j + a[i]; if (t > 10000) { suf += tab[j]; suf %= MOD; } else { tmp[t] = 1; tab[t] += tab[j]; tab[t] %= MOD; } } } int s = suf; for (int i = 1; i <= 10000; i++) { //if (tab[i]) //printf("i = %d, tab = %d\n", i, tab[i]); s += tab[i]; s %= MOD; } printf("%d\n", s); 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 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 82 83 84 85 86 87 88 89 | #include <cstdio> #include <algorithm> using namespace std; const int MOD = 1000000007; int a[5001]; int tab[10001]; int tmp[10001]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", a + i); } sort(a, a + n); tab[0] = 1; tmp[0] = 1; int T = 1; int suf = 0; for (int i = 0; i < n; i++) { int c = 0; //int k = T - 1; int first = -1; bool ok = true; for (int j = 10000; j >= 0; j--) { if (tmp[j]) { if (first == -1) { first = 1; if (j < a[i] - 1) { ok = false; break; } } } } if (!ok) break; suf *= 2; suf %= MOD; for (int j = 10000; j >= 0; j--) { if (!tmp[j]) continue; if (j < a[i] - 1) break; int t = j + a[i]; if (t > 10000) { suf += tab[j]; suf %= MOD; } else { tmp[t] = 1; tab[t] += tab[j]; tab[t] %= MOD; } } } int s = suf; for (int i = 1; i <= 10000; i++) { //if (tab[i]) //printf("i = %d, tab = %d\n", i, tab[i]); s += tab[i]; s %= MOD; } printf("%d\n", s); return 0; } |