#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, max_s = 0; cin >> n; const int mod = 1e9 + 7; vector<int> v(n); for (auto &x : v) { cin >> x; max_s += x; } sort(v.begin(), v.end()); vector<vector<int>> dp(2, vector<int>(max_s+1)); if (v[0] != 1) { cout << 0; return 0; } dp[0][1] = 1; for (int i = 1; i < n; ++i) { dp[1] = dp[0]; dp[1][1] += v[i] == 1; for (int s = v[i]-1; s <= max_s-v[i]; ++s) { dp[1][s+v[i]] = (dp[1][s+v[i]] + dp[0][s]) % mod; } swap(dp[0], dp[1]); } int ans = 0; for (int i = 1; i <= max_s; ++i) ans += dp[0][i]; ans %= mod; cout << ans << '\n'; } // 5 // 1 2 4 4 7 // 19 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // 18 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
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 | #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, max_s = 0; cin >> n; const int mod = 1e9 + 7; vector<int> v(n); for (auto &x : v) { cin >> x; max_s += x; } sort(v.begin(), v.end()); vector<vector<int>> dp(2, vector<int>(max_s+1)); if (v[0] != 1) { cout << 0; return 0; } dp[0][1] = 1; for (int i = 1; i < n; ++i) { dp[1] = dp[0]; dp[1][1] += v[i] == 1; for (int s = v[i]-1; s <= max_s-v[i]; ++s) { dp[1][s+v[i]] = (dp[1][s+v[i]] + dp[0][s]) % mod; } swap(dp[0], dp[1]); } int ans = 0; for (int i = 1; i <= max_s; ++i) ans += dp[0][i]; ans %= mod; cout << ans << '\n'; } // 5 // 1 2 4 4 7 // 19 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 // 18 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |