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
#include <cstdio>
#include <algorithm>

const int max_n = 5010;
const int mod = 1000000007;

int n, m;
int a[max_n];
int dp[2][max_n];

int main() {
    scanf ("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    std::sort(a, a + n);
    m = a[n - 1] + 1;
    for (int i = 0; i <= m; ++i) dp[0][i] = 0;
    dp[0][0] = 1;

    int side = 0;
    for (int i = 0; i < n; ++i) {
        side = 1 - side;
        for (int j = 0; j <= m; ++j) dp[side][j] = dp[1 - side][j];
        for (int j = a[i] - 1; j <= m; ++j) {
            int nxt = std::min(j + a[i], m);
            dp[side][nxt] += dp[1 - side][j];
            if (dp[side][nxt] >= mod) dp[side][nxt] -= mod;
        }
    }
    long long ret = 0;
    for (int i = 1; i <= m; ++i) ret += dp[side][i];
    printf("%lld\n", ret % mod);
    return 0;
}