#include<bits/stdc++.h> using namespace std; constexpr int N=5e3+5, P=1e9+7; vector<int>tab; long long dp[N], dwa[N]; int main() { int n,a; long long ans=0; dp[0]=1; dwa[0]=1; scanf("%d", &n); for(int i=0;i<n;++i) { scanf("%d", &a); tab.push_back(a); dwa[i+1]=dwa[i]*2; dwa[i+1]%=P; //cout << "dwa[i]= " << dwa[i] << endl; } sort(tab.begin(), tab.end()); int pozostale=n-1; for(auto e:tab) { //cout << "pozostale = " << pozostale << endl; //cout << "dwa pozostale = " << dwa[pozostale] << endl; for(int i=N-5;i>=0;--i) { if(i>=e-1) //i=i-e { if(i+e<=5000) { dp[i+e]+=dp[i]; dp[i+e]%=P; } else { ans+=dp[i]*dwa[pozostale]; ans%=P; } } else break; } --pozostale; /*cout << "po dodaniu: " << e << endl; for(int i=1;i<20;++i) { cout << dp[i] << endl; } cout << "========" << endl;*/ } for(int i=1;i<N;++i) { //cout << dp[i] << endl; ans+=dp[i]; ans%=P; } printf("%lld", ans); 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 | #include<bits/stdc++.h> using namespace std; constexpr int N=5e3+5, P=1e9+7; vector<int>tab; long long dp[N], dwa[N]; int main() { int n,a; long long ans=0; dp[0]=1; dwa[0]=1; scanf("%d", &n); for(int i=0;i<n;++i) { scanf("%d", &a); tab.push_back(a); dwa[i+1]=dwa[i]*2; dwa[i+1]%=P; //cout << "dwa[i]= " << dwa[i] << endl; } sort(tab.begin(), tab.end()); int pozostale=n-1; for(auto e:tab) { //cout << "pozostale = " << pozostale << endl; //cout << "dwa pozostale = " << dwa[pozostale] << endl; for(int i=N-5;i>=0;--i) { if(i>=e-1) //i=i-e { if(i+e<=5000) { dp[i+e]+=dp[i]; dp[i+e]%=P; } else { ans+=dp[i]*dwa[pozostale]; ans%=P; } } else break; } --pozostale; /*cout << "po dodaniu: " << e << endl; for(int i=1;i<20;++i) { cout << dp[i] << endl; } cout << "========" << endl;*/ } for(int i=1;i<N;++i) { //cout << dp[i] << endl; ans+=dp[i]; ans%=P; } printf("%lld", ans); return 0; } |