#include <iostream> using namespace std; int events[5005]; long long suma; long long x[5005]; long long ans; long long mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { int a; cin >> a; events[a]++; } suma = 1; x[0] = 1; for (int i = 1; i <= 5000; i++) { for (int j = 0; j < events[i]; j++) { ans += suma; if (ans >= mod) ans -= mod; for (int k = 5001; k >= i - 1; k--) { suma += x[k]; if (suma >= mod) suma -= mod; x[min (5001, k + i)] += x[k]; if (x[min (5001, k + i)] >= mod) x[min (5001, k + i)] -= mod; } } suma -= x[i - 1]; if (suma < 0) suma += mod; } cout << ans; }
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 | #include <iostream> using namespace std; int events[5005]; long long suma; long long x[5005]; long long ans; long long mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { int a; cin >> a; events[a]++; } suma = 1; x[0] = 1; for (int i = 1; i <= 5000; i++) { for (int j = 0; j < events[i]; j++) { ans += suma; if (ans >= mod) ans -= mod; for (int k = 5001; k >= i - 1; k--) { suma += x[k]; if (suma >= mod) suma -= mod; x[min (5001, k + i)] += x[k]; if (x[min (5001, k + i)] >= mod) x[min (5001, k + i)] -= mod; } } suma -= x[i - 1]; if (suma < 0) suma += mod; } cout << ans; } |