#include <bits/stdc++.h> #define f first #define s second #define pb push_back #define mp make_pair #define ins insert #define er erase #define siz size() #define siz1 size()-1 #define ll long long #define ull unsigned long long #define all(v) v.begin(), v.end() #define FORN(i, n) for(int i=1; i<=(int)n; i++) #define FOR(i,p,k) for(int i=(int)p; i<=(int)k; i++) #define FORD(i, k, p) for(int i=(int)k; i>=(int)p; i--) #define FOR0(i, n) for(int i=(int)n; i>=0; i--) #define FOR1(i, n) for(int i=(int)n; i>=1; i--) #define FORV(i, vec) for(auto i = vec.begin(); i != vec.end(); ++i) #define TURBO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define END cerr<<"TIME: "<<1.0 * clock() / CLOCKS_PER_SEC<<endl; #define VI vector <int> #define VP vector <pair<int, int>> #define VIP vector <pair<int, pair<int, int>>> #define VPP vector <pair<pair<int, int>, pair<int, int>>> #define MII map<int, int> #define MLL map<ll, ll> #define PII pair<int, int> #define PLL pair<ll, ll> #define MAX 1e9 + 10 #define MIN -1e9 + 10 using namespace std; const int MOD = 1e9 + 7; ll DP[5000+5]; int main() { TURBO; int n; cin>>n; VI v; int a; for(int i=1; i<=n; i++) { cin>>a; v.pb(a); } sort(all(v)); ll OPTIONS_WITH_SUM_OVER_5000 = 0; DP[0] = 1; for(int i=0; i<v.size(); i++) { int element = v[i]; OPTIONS_WITH_SUM_OVER_5000 *= 2; if(OPTIONS_WITH_SUM_OVER_5000 >= MOD) OPTIONS_WITH_SUM_OVER_5000 -= MOD; for(int sum=5000; sum>5000-element; sum--) ///suma przekraczajaca 5000 { if (sum >= element -1) { OPTIONS_WITH_SUM_OVER_5000 += DP[sum]; if(OPTIONS_WITH_SUM_OVER_5000 >= MOD) OPTIONS_WITH_SUM_OVER_5000 -= MOD; } } for(int sum=5000-element; sum>=element-1; sum--) { if (DP[sum] > 0) { DP[sum+element] += DP[sum]; if (DP[sum+element] >= MOD) DP[sum+element] -= MOD; } } } ll all_options_sum = OPTIONS_WITH_SUM_OVER_5000; for(int i=1; i<=5000; i++) { all_options_sum += DP[i]; if(all_options_sum >= MOD) all_options_sum -= MOD; } cout<<all_options_sum; 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | #include <bits/stdc++.h> #define f first #define s second #define pb push_back #define mp make_pair #define ins insert #define er erase #define siz size() #define siz1 size()-1 #define ll long long #define ull unsigned long long #define all(v) v.begin(), v.end() #define FORN(i, n) for(int i=1; i<=(int)n; i++) #define FOR(i,p,k) for(int i=(int)p; i<=(int)k; i++) #define FORD(i, k, p) for(int i=(int)k; i>=(int)p; i--) #define FOR0(i, n) for(int i=(int)n; i>=0; i--) #define FOR1(i, n) for(int i=(int)n; i>=1; i--) #define FORV(i, vec) for(auto i = vec.begin(); i != vec.end(); ++i) #define TURBO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define END cerr<<"TIME: "<<1.0 * clock() / CLOCKS_PER_SEC<<endl; #define VI vector <int> #define VP vector <pair<int, int>> #define VIP vector <pair<int, pair<int, int>>> #define VPP vector <pair<pair<int, int>, pair<int, int>>> #define MII map<int, int> #define MLL map<ll, ll> #define PII pair<int, int> #define PLL pair<ll, ll> #define MAX 1e9 + 10 #define MIN -1e9 + 10 using namespace std; const int MOD = 1e9 + 7; ll DP[5000+5]; int main() { TURBO; int n; cin>>n; VI v; int a; for(int i=1; i<=n; i++) { cin>>a; v.pb(a); } sort(all(v)); ll OPTIONS_WITH_SUM_OVER_5000 = 0; DP[0] = 1; for(int i=0; i<v.size(); i++) { int element = v[i]; OPTIONS_WITH_SUM_OVER_5000 *= 2; if(OPTIONS_WITH_SUM_OVER_5000 >= MOD) OPTIONS_WITH_SUM_OVER_5000 -= MOD; for(int sum=5000; sum>5000-element; sum--) ///suma przekraczajaca 5000 { if (sum >= element -1) { OPTIONS_WITH_SUM_OVER_5000 += DP[sum]; if(OPTIONS_WITH_SUM_OVER_5000 >= MOD) OPTIONS_WITH_SUM_OVER_5000 -= MOD; } } for(int sum=5000-element; sum>=element-1; sum--) { if (DP[sum] > 0) { DP[sum+element] += DP[sum]; if (DP[sum+element] >= MOD) DP[sum+element] -= MOD; } } } ll all_options_sum = OPTIONS_WITH_SUM_OVER_5000; for(int i=1; i<=5000; i++) { all_options_sum += DP[i]; if(all_options_sum >= MOD) all_options_sum -= MOD; } cout<<all_options_sum; return 0; } |