#include<bits/stdc++.h> using namespace std; int n,a[5004],MOD = 1000000000 + 7,w,dp[5004],suma; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; for(int i = 0;i < n; i++) cin>>a[i]; sort(a,a + n); dp[0] = 1; for(int i = 0;i < n; i++) { suma = (suma * 2) % MOD; for(int j = 4999;j >= a[i] - 1; j--) if(j + a[i] < 5000) dp[j + a[i]] = (dp[a[i] + j] + dp[j]) % MOD; else suma = (suma + dp[j]) % MOD; } w = (w + suma) % MOD; for(int i = 1;i < 5000; i++) w = (w + dp[i]) % MOD; cout<<w<<'\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 | #include<bits/stdc++.h> using namespace std; int n,a[5004],MOD = 1000000000 + 7,w,dp[5004],suma; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; for(int i = 0;i < n; i++) cin>>a[i]; sort(a,a + n); dp[0] = 1; for(int i = 0;i < n; i++) { suma = (suma * 2) % MOD; for(int j = 4999;j >= a[i] - 1; j--) if(j + a[i] < 5000) dp[j + a[i]] = (dp[a[i] + j] + dp[j]) % MOD; else suma = (suma + dp[j]) % MOD; } w = (w + suma) % MOD; for(int i = 1;i < 5000; i++) w = (w + dp[i]) % MOD; cout<<w<<'\n'; return 0; } |