#include <bits/stdc++.h> using namespace std; int MAX_N = 5000; int MOD = 1000 * 1000 * 1000 + 7; int add(int a, int b) { int res = a + b; if (res >= MOD) { res -= MOD; } return res; } signed main() { vector <int> res(MAX_N + 1); int big = 0; res[0] = 1; int n; cin >> n; vector <int> in(n); for (int i = 0; i < n; i++) { cin >> in[i]; } sort(in.begin(), in.end()); for (int i = 0; i < n; i++) { big = add(big, big); for (int j = 5000; j >= in[i] - 1; j--) { int where = j + in[i]; if (where <= MAX_N) { res[where] = add(res[where], res[j]); } else { big = add(big, res[j]); } } } int result = big; for (int i = 1; i <= MAX_N; i++) { result = add(result, res[i]); } cout << result << endl; 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 | #include <bits/stdc++.h> using namespace std; int MAX_N = 5000; int MOD = 1000 * 1000 * 1000 + 7; int add(int a, int b) { int res = a + b; if (res >= MOD) { res -= MOD; } return res; } signed main() { vector <int> res(MAX_N + 1); int big = 0; res[0] = 1; int n; cin >> n; vector <int> in(n); for (int i = 0; i < n; i++) { cin >> in[i]; } sort(in.begin(), in.end()); for (int i = 0; i < n; i++) { big = add(big, big); for (int j = 5000; j >= in[i] - 1; j--) { int where = j + in[i]; if (where <= MAX_N) { res[where] = add(res[where], res[j]); } else { big = add(big, res[j]); } } } int result = big; for (int i = 1; i <= MAX_N; i++) { result = add(result, res[i]); } cout << result << endl; return 0; } |