#include <bits/stdc++.h>
using namespace std;
const long long M = 1000000007;
int n;
long long a[6000];
long long dp[10000];
int main(){
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; ++i)
{
cin >> a[i];
}
sort(a, a + n);
long long ans = 0;
dp[0] = 1;
for (int i = 0; i < n; ++i)
{
//cout << ans << endl;
for (int s = 4999; s >= 0; --s)
{
if(s < 4999){
if(a[i] <= s + 1){
dp[min(s + a[i], (long long)4999)] = (dp[min(s + a[i], (long long)4999)] + dp[s]) % M;
ans = (ans + dp[s]) % M;
}
}
else{
ans = (ans + dp[s]) % M;
dp[s] = (2 * dp[s]) % M;
}
//cout << dp[4999] << endl;
}
}
cout << ans << endl;
}
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 | #include <bits/stdc++.h> using namespace std; const long long M = 1000000007; int n; long long a[6000]; long long dp[10000]; int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; } sort(a, a + n); long long ans = 0; dp[0] = 1; for (int i = 0; i < n; ++i) { //cout << ans << endl; for (int s = 4999; s >= 0; --s) { if(s < 4999){ if(a[i] <= s + 1){ dp[min(s + a[i], (long long)4999)] = (dp[min(s + a[i], (long long)4999)] + dp[s]) % M; ans = (ans + dp[s]) % M; } } else{ ans = (ans + dp[s]) % M; dp[s] = (2 * dp[s]) % M; } //cout << dp[4999] << endl; } } cout << ans << endl; } |
English