#include <iostream> #include <vector> #include <algorithm> using namespace std; constexpr uint32_t M = 1000000007; const size_t max_index = 5001; size_t cap(size_t i){ return (i>max_index)?max_index:i; } int main(){ int n; cin>>n; vector<int> a; a.reserve(n); // int sum = 0; for(int i=0; i<n; i++){ int t; cin>>t; // sum+=t; a.push_back(t); } // sum = sum*2; vector<int64_t> c; sort(begin(a), end(a)); if (a[0]!=1){ cout<<0<<endl; return 0; } c.resize(max_index+1); c[0]=1; for (auto it = begin(a); it!=end(a); it++){ int ai = *it; for (int i=max_index; i>=ai-1; i-- ){ c[cap(i+ai)] = (c[i]+ c[cap(i+ai)])%M; } } int64_t total = 0; for (auto a : c){ total = (a+total)%M; } cout << total-1 << 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; constexpr uint32_t M = 1000000007; const size_t max_index = 5001; size_t cap(size_t i){ return (i>max_index)?max_index:i; } int main(){ int n; cin>>n; vector<int> a; a.reserve(n); // int sum = 0; for(int i=0; i<n; i++){ int t; cin>>t; // sum+=t; a.push_back(t); } // sum = sum*2; vector<int64_t> c; sort(begin(a), end(a)); if (a[0]!=1){ cout<<0<<endl; return 0; } c.resize(max_index+1); c[0]=1; for (auto it = begin(a); it!=end(a); it++){ int ai = *it; for (int i=max_index; i>=ai-1; i-- ){ c[cap(i+ai)] = (c[i]+ c[cap(i+ai)])%M; } } int64_t total = 0; for (auto a : c){ total = (a+total)%M; } cout << total-1 << endl; return 0; } |