#include <bits/stdc++.h> using namespace std; typedef long long ll; ll M = 1000LL * 1000LL * 1000LL + 7LL; const int N = 5 * 1000 + 7; ll ile[N * N / 2 + 7]; int tab[N]; void Licz(int n) { int i, j, ak, m; ll w; ile[0] = 1LL; sort(tab + 1, tab + 1 + n); m = 0; for(i = 1; i <= n; ++i) { ak = tab[i]; j = m + ak; while(j >= ak - 1 + ak) { m = max(m, j); ile[j] += ile[j - ak]; ile[j] %= M; //cout << j << " " << ak << " " << ile[j] << "\n"; --j; } } w = 0LL; //cout << m << "\n"; for(i = 1; i <= m; ++i) { //cout << i << " " << ile[i] << "\n"; w += ile[i]; w %= M; } cout << w << "\n"; } void Wczytaj(int &n) { int i; cin >> n; for(i = 1; i <= n; ++i) cin >> tab[i]; } void Cukiernia() { int n; Wczytaj(n); Licz(n); } int main () { ios_base::sync_with_stdio(false); cin.tie(nullptr); Cukiernia(); 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 <bits/stdc++.h> using namespace std; typedef long long ll; ll M = 1000LL * 1000LL * 1000LL + 7LL; const int N = 5 * 1000 + 7; ll ile[N * N / 2 + 7]; int tab[N]; void Licz(int n) { int i, j, ak, m; ll w; ile[0] = 1LL; sort(tab + 1, tab + 1 + n); m = 0; for(i = 1; i <= n; ++i) { ak = tab[i]; j = m + ak; while(j >= ak - 1 + ak) { m = max(m, j); ile[j] += ile[j - ak]; ile[j] %= M; //cout << j << " " << ak << " " << ile[j] << "\n"; --j; } } w = 0LL; //cout << m << "\n"; for(i = 1; i <= m; ++i) { //cout << i << " " << ile[i] << "\n"; w += ile[i]; w %= M; } cout << w << "\n"; } void Wczytaj(int &n) { int i; cin >> n; for(i = 1; i <= n; ++i) cin >> tab[i]; } void Cukiernia() { int n; Wczytaj(n); Licz(n); } int main () { ios_base::sync_with_stdio(false); cin.tie(nullptr); Cukiernia(); return 0; } |