#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define ST first #define ND second #define PB push_back #define SIZE(a) ((int)a.size()) template<class T, class U> ostream& operator<<(ostream &stream, pair<T, U> &p) { stream << "(" << p.ST << "," << p.ND << ")"; return stream; } template<class T> ostream& operator<<(ostream &stream, vector<T> &v) { stream << "["; for(auto elem : v) { stream << elem << ", "; } stream << "]"; return stream; } const int mod = 1e9+7; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector<int> a(n); int a_sum = 0; for(int &x : a) { cin >> x; a_sum+=x; } sort(a.begin(), a.end()); vector<int> dp(a_sum+1); dp[0] = 1; int cum_sum = 0; for(int x : a) { cum_sum+= x; for(int i=cum_sum; i-x >= x-1; i--) { dp[i] = (dp[i]+dp[i-x])%mod; } // cout << dp << "\n"; } int res=-1; for(int x : dp) { res = (res+x)%mod; } cout << (res+mod)%mod << "\n"; }
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 | #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define ST first #define ND second #define PB push_back #define SIZE(a) ((int)a.size()) template<class T, class U> ostream& operator<<(ostream &stream, pair<T, U> &p) { stream << "(" << p.ST << "," << p.ND << ")"; return stream; } template<class T> ostream& operator<<(ostream &stream, vector<T> &v) { stream << "["; for(auto elem : v) { stream << elem << ", "; } stream << "]"; return stream; } const int mod = 1e9+7; int main() { ios_base::sync_with_stdio(0); int n; cin >> n; vector<int> a(n); int a_sum = 0; for(int &x : a) { cin >> x; a_sum+=x; } sort(a.begin(), a.end()); vector<int> dp(a_sum+1); dp[0] = 1; int cum_sum = 0; for(int x : a) { cum_sum+= x; for(int i=cum_sum; i-x >= x-1; i--) { dp[i] = (dp[i]+dp[i-x])%mod; } // cout << dp << "\n"; } int res=-1; for(int x : dp) { res = (res+x)%mod; } cout << (res+mod)%mod << "\n"; } |