#include <iostream> #include <vector> #include <algorithm> using namespace std; const int P=1000000000+7; typedef long long LL; int ile[5010*5010], ost, n; vector<int> a; int szybciej(int od) { for (int i=1; i<=5000; ++i) if (!ile[i]) ;//return -1; LL sp=0; for (int i=5001; i<=ost; ++i) sp+=ile[i]; sp%=P; LL wyn=0; for (int i=od; i<n; ++i) { wyn+=sp; sp*=2; int b=a[i]; for (int j=5000; b-1<=j; --j) { int x=ile[j]; if (j+b<=5000) { int &jb=ile[j+b]; jb+=x; if (P<=jb) jb-=P; } else sp+=x; wyn+=x; } sp%=P; wyn%=P; } return wyn; } int main() { cin>>n; for (int i=0; i<n; ++i) { int b; cin>>b; a.push_back(b); } // n=5000; // for (int i=1; i<=n; ++i) // a.push_back(i); sort(a.begin(), a.end()); LL wyn=0; ile[0]=1; cout<<szybciej(0)<<endl; return 0; for (int i=0; i<n; ++i) { cout<<i<<endl; int b=a[i]; for (int j=ost; b-1<=j; --j) { int x=ile[j]; if (x) { int &jb=ile[j+b]; jb+=x; if (P<=jb) jb-=P; wyn+=x; ost=max(ost, j+b); } } wyn%=P; int sz=szybciej(i+1); if (sz!=-1) { wyn=(wyn+sz)%P; break; } } cout<<wyn<<endl; 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; const int P=1000000000+7; typedef long long LL; int ile[5010*5010], ost, n; vector<int> a; int szybciej(int od) { for (int i=1; i<=5000; ++i) if (!ile[i]) ;//return -1; LL sp=0; for (int i=5001; i<=ost; ++i) sp+=ile[i]; sp%=P; LL wyn=0; for (int i=od; i<n; ++i) { wyn+=sp; sp*=2; int b=a[i]; for (int j=5000; b-1<=j; --j) { int x=ile[j]; if (j+b<=5000) { int &jb=ile[j+b]; jb+=x; if (P<=jb) jb-=P; } else sp+=x; wyn+=x; } sp%=P; wyn%=P; } return wyn; } int main() { cin>>n; for (int i=0; i<n; ++i) { int b; cin>>b; a.push_back(b); } // n=5000; // for (int i=1; i<=n; ++i) // a.push_back(i); sort(a.begin(), a.end()); LL wyn=0; ile[0]=1; cout<<szybciej(0)<<endl; return 0; for (int i=0; i<n; ++i) { cout<<i<<endl; int b=a[i]; for (int j=ost; b-1<=j; --j) { int x=ile[j]; if (x) { int &jb=ile[j+b]; jb+=x; if (P<=jb) jb-=P; wyn+=x; ost=max(ost, j+b); } } wyn%=P; int sz=szybciej(i+1); if (sz!=-1) { wyn=(wyn+sz)%P; break; } } cout<<wyn<<endl; return 0; } |