#include<iostream> #include<algorithm> using namespace std; const int MAX_N = 5007; const int MAX_A = 5007; const long long MOD = 1000000007; int a[MAX_N]; long long plec[MAX_A], plecHigh; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; sort(a, a+n); plec[0] = 1; for(int i = 0; i < n; i++) { plecHigh = (plecHigh*2) % MOD; for(int j = MAX_A-1; j >= a[i]-1; j--) { if(j+a[i] >= MAX_A) plecHigh = (plecHigh + plec[j]) % MOD; else plec[j+a[i]] = (plec[j+a[i]]+plec[j]) % MOD; } } for(int i = 1; i < MAX_A; i++) { plecHigh = (plecHigh + plec[i]) % MOD; } cout << plecHigh << "\n"; 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 | #include<iostream> #include<algorithm> using namespace std; const int MAX_N = 5007; const int MAX_A = 5007; const long long MOD = 1000000007; int a[MAX_N]; long long plec[MAX_A], plecHigh; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; sort(a, a+n); plec[0] = 1; for(int i = 0; i < n; i++) { plecHigh = (plecHigh*2) % MOD; for(int j = MAX_A-1; j >= a[i]-1; j--) { if(j+a[i] >= MAX_A) plecHigh = (plecHigh + plec[j]) % MOD; else plec[j+a[i]] = (plec[j+a[i]]+plec[j]) % MOD; } } for(int i = 1; i < MAX_A; i++) { plecHigh = (plecHigh + plec[i]) % MOD; } cout << plecHigh << "\n"; return 0; } |