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

const int P = 1000000007;

int main() {
    int N;
    std::vector<int> A;

    scanf("%d", &N);
    A.resize(N+1);
    A[0]=0;
    for (int i=1; i<=N; ++i) {
        scanf("%d", &A[i]);
    }

    std::sort(A.begin()++, A.end());

    std::vector<std::vector<int> > dp;
    dp.resize(N+1);
    dp[0].resize(5001);
    dp[0][0] = 1;
        
    for (int i=1; i<=N; ++i) {
        dp[i].resize(5001);
        for (int j=0; j<=5000; ++j) {
            dp[i][j] = (dp[i][j] + dp[i-1][j]) % P;
            if (j+1 >= A[i]) {
                int pos = std::min(j+A[i], 5000);
                dp[i][pos] = (dp[i][pos] + dp[i-1][j]) % P;
            }
        }
    }

    int result = 0;
    for (int j=1; j<=5000; ++j) {
        result = (result + dp[N][j]) % P;
    }

    printf("%d\n", result);
    return 0;
}