#include<cstdio> #include<algorithm> #include<map> typedef std::map<int, int> mi; typedef mi::iterator miit; int n; int * c; int p = 1000000007; mi m; int maxc; void input() { scanf("%d", &n); c = new int[n]; for (int i = 0; i < n; i++) { scanf("%d", c + i); } std::sort(c, c + n); maxc = c[n - 1]; } void print() { printf("\n"); for (miit it = m.begin(); it != m.end(); it++) { printf("%d %d\n", it -> first, it -> second); } } int solve() { long long res = 0; m[0] = 1; // print(); for (int i = 0; i < n; i++) { // printf("%d\n", c[i]); miit it = --m.end(); while (it != m.begin() && c[i] - 1 <= it -> first) { m[it -> first + c[i]] = (m[it -> first + c[i]] + it -> second) % p; it--; } if (c[i] - 1 <= it -> first) { m[it -> first + c[i]] = (m[it -> first + c[i]] + it -> second) % p; } // print(); int mm = 0; for (miit it = m.upper_bound(maxc); it != m.end(); it++) { mm = (mm + it -> second) % p; } m.erase(m.upper_bound(maxc), m.end()); m[maxc] = (m[maxc] + mm) % p; // print(); } for (miit it = ++m.begin(); it != m.end(); it++) { res = (res + it -> second) % p; } return (int) res; } int main() { input(); printf("%d\n", solve()); 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 64 65 | #include<cstdio> #include<algorithm> #include<map> typedef std::map<int, int> mi; typedef mi::iterator miit; int n; int * c; int p = 1000000007; mi m; int maxc; void input() { scanf("%d", &n); c = new int[n]; for (int i = 0; i < n; i++) { scanf("%d", c + i); } std::sort(c, c + n); maxc = c[n - 1]; } void print() { printf("\n"); for (miit it = m.begin(); it != m.end(); it++) { printf("%d %d\n", it -> first, it -> second); } } int solve() { long long res = 0; m[0] = 1; // print(); for (int i = 0; i < n; i++) { // printf("%d\n", c[i]); miit it = --m.end(); while (it != m.begin() && c[i] - 1 <= it -> first) { m[it -> first + c[i]] = (m[it -> first + c[i]] + it -> second) % p; it--; } if (c[i] - 1 <= it -> first) { m[it -> first + c[i]] = (m[it -> first + c[i]] + it -> second) % p; } // print(); int mm = 0; for (miit it = m.upper_bound(maxc); it != m.end(); it++) { mm = (mm + it -> second) % p; } m.erase(m.upper_bound(maxc), m.end()); m[maxc] = (m[maxc] + mm) % p; // print(); } for (miit it = ++m.begin(); it != m.end(); it++) { res = (res + it -> second) % p; } return (int) res; } int main() { input(); printf("%d\n", solve()); return 0; } |