#include<bits/stdc++.h> #define ll long long const ll MOD = 1000000007; using namespace std; ll dp[25000009]; int val[5009]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for(int i = 0; i < n; i++) cin >> val[i]; sort(val, val + n); dp[0] = 1; int maxsum = 0; for(int i = 0; i < n; i++) { int curr = maxsum; while(curr >= val[i] - 1) { if(dp[curr] != 0 and curr + val[i] <= 25000000) { maxsum = max(maxsum, curr + val[i]); dp[curr + val[i]] += dp[curr]; dp[curr + val[i]] %= MOD; } curr--; } } ll res = 0; for(int i = 1; i <= maxsum; i++) { res += dp[i]; res %= MOD; } cout << res << "\n"; 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 | #include<bits/stdc++.h> #define ll long long const ll MOD = 1000000007; using namespace std; ll dp[25000009]; int val[5009]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for(int i = 0; i < n; i++) cin >> val[i]; sort(val, val + n); dp[0] = 1; int maxsum = 0; for(int i = 0; i < n; i++) { int curr = maxsum; while(curr >= val[i] - 1) { if(dp[curr] != 0 and curr + val[i] <= 25000000) { maxsum = max(maxsum, curr + val[i]); dp[curr + val[i]] += dp[curr]; dp[curr + val[i]] %= MOD; } curr--; } } ll res = 0; for(int i = 1; i <= maxsum; i++) { res += dp[i]; res %= MOD; } cout << res << "\n"; return 0; } |