#include <algorithm> #include <cstdio> #define ll long long const ll B = 1000000007LL; using namespace std; ll s1[5555]; ll s2[5555]; int main(int argc, char** argv) { int n; int a[5000]; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d", &(a[i])); } sort(a, a + n); int mx = a[n-1]; ll* p = s1; ll* d = s2; if(a[0] == 1) { p[1] = 1LL%B; } for(int i=1;i<n;i++) { fill(d, d+(mx+1), 0); int v = a[i]; if(v == 1) { d[1] = 1LL%B; } for(int j=0;j<=mx;j++) { d[j] += p[j]; d[j] %= B; if(v <= j+1) { if(p[j] > 0) { int x = min(mx, j+v); d[x] += p[j]; d[x] %= B; } } } ll* t = p; p = d; d = t; } ll res = 0LL%B; for(int i=0;i<=mx;i++) { res += p[i]; res %= B; } printf("%lld\n", res); 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 | #include <algorithm> #include <cstdio> #define ll long long const ll B = 1000000007LL; using namespace std; ll s1[5555]; ll s2[5555]; int main(int argc, char** argv) { int n; int a[5000]; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d", &(a[i])); } sort(a, a + n); int mx = a[n-1]; ll* p = s1; ll* d = s2; if(a[0] == 1) { p[1] = 1LL%B; } for(int i=1;i<n;i++) { fill(d, d+(mx+1), 0); int v = a[i]; if(v == 1) { d[1] = 1LL%B; } for(int j=0;j<=mx;j++) { d[j] += p[j]; d[j] %= B; if(v <= j+1) { if(p[j] > 0) { int x = min(mx, j+v); d[x] += p[j]; d[x] %= B; } } } ll* t = p; p = d; d = t; } ll res = 0LL%B; for(int i=0;i<=mx;i++) { res += p[i]; res %= B; } printf("%lld\n", res); return 0; } |