#include <cstdio> #include <algorithm> #include <vector> using namespace std; typedef long long LL; typedef vector<LL> VI; const LL N = 5000; const LL MOD = 1e9 + 7; LL x[N]; int main() { LL n, s = 0; scanf("%lld", &n); for (LL i = 0; i < n; ++i) { scanf("%lld", &x[i]); s += x[i]; } sort(x, x + n); VI d(s + 1); d[0] = 1; s = 0; for (LL i = 0; i < n; ++i) { s += x[i]; for (LL j = s; j >= 2*x[i] - 1; --j) { d[j] = (d[j] + d[j - x[i]]) % MOD; } } LL r = 0; for (LL i = 1; i <= s; ++i) r = (r + d[i]) % MOD; printf("%lld\n", r); 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 | #include <cstdio> #include <algorithm> #include <vector> using namespace std; typedef long long LL; typedef vector<LL> VI; const LL N = 5000; const LL MOD = 1e9 + 7; LL x[N]; int main() { LL n, s = 0; scanf("%lld", &n); for (LL i = 0; i < n; ++i) { scanf("%lld", &x[i]); s += x[i]; } sort(x, x + n); VI d(s + 1); d[0] = 1; s = 0; for (LL i = 0; i < n; ++i) { s += x[i]; for (LL j = s; j >= 2*x[i] - 1; --j) { d[j] = (d[j] + d[j - x[i]]) % MOD; } } LL r = 0; for (LL i = 1; i <= s; ++i) r = (r + d[i]) % MOD; printf("%lld\n", r); return 0; } |