//Author: Piotr Zielinski
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, int> PII;
const int N = 5e3+10;
const LL MOD = 1e9+7;
vector<LL> m(N);
vector<LL> m2(N);
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
int n;
cin >> n;
vector<LL> in(n);
for(auto &I : in) {
cin >> I;
}
sort(in.begin(), in.end());
m[0] = 1;
m2[0] = 1;
LL res = 0, add = 0, add2 = 0;
for(int i = 0;i < n;++i) {
add2 = 0;
for(int j = 0;j < 5006;++j) {
if(in[i] <= j + 1) {
if(j + in[i] > 5005) {
add2 += m[j];
add2 %= MOD;
// cout << in[i] << " " << I.second << endl;
}
else {
m2[j + in[i]] += m[j];
m2[j + in[i]] %= MOD;
}
}
}
m = m2;
add += add + add2;
add %= MOD;
}
m[0] = 0;
for(auto &I : m) {
// cout << I.first << " -> " << I.second << "\n";
res += I;
res %= MOD;
}
res += add;
res %= MOD;
cout << res << "\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 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 | //Author: Piotr Zielinski #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL, int> PII; const int N = 5e3+10; const LL MOD = 1e9+7; vector<LL> m(N); vector<LL> m2(N); int main() { ios::sync_with_stdio(0); cin.tie(nullptr); int n; cin >> n; vector<LL> in(n); for(auto &I : in) { cin >> I; } sort(in.begin(), in.end()); m[0] = 1; m2[0] = 1; LL res = 0, add = 0, add2 = 0; for(int i = 0;i < n;++i) { add2 = 0; for(int j = 0;j < 5006;++j) { if(in[i] <= j + 1) { if(j + in[i] > 5005) { add2 += m[j]; add2 %= MOD; // cout << in[i] << " " << I.second << endl; } else { m2[j + in[i]] += m[j]; m2[j + in[i]] %= MOD; } } } m = m2; add += add + add2; add %= MOD; } m[0] = 0; for(auto &I : m) { // cout << I.first << " -> " << I.second << "\n"; res += I; res %= MOD; } res += add; res %= MOD; cout << res << "\n"; return 0; } |
English