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

int mem[2][25000100];
const int LARGE_PRIME = 1000000007;

int n;
int ans;
int a[5010];
int s[5010];

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);

    std::sort(a, a + n);

    s[0] = 0;
    for (int i = 0; i < n; ++i) s[i + 1] = s[i] + a[i];

    if (a[0] != 1)
    {
        printf("0\n");
        return 0;
    }
    mem[0][0] = 1;
    int last, next, cur;
    for (int i = 0; i < n; ++i)
    {
        cur = i & 1;
        next = (i + 1) & 1;
        for (int j = 0; j <= s[i]; ++j) mem[next][j] = mem[cur][j];
        last = i + 1;

        if (a[i] - 1 > s[i]) break;
        for (int j = a[i] - 1; j <= s[i]; ++j)
        {
            if (mem[cur][j] == 0) continue;
            mem[next][j + a[i]] += mem[cur][j];
            mem[next][j + a[i]] %= LARGE_PRIME;
        }
    }
    ans = 0;
    cur = last & 1;
    for (int j = 1; j <= s[last]; ++j) { ans += mem[cur][j]; ans %= LARGE_PRIME; }

    printf("%d\n", ans);

    return 0;
}