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

using namespace std;

static const int P = 1e9+7;

static int tab[5001][5001];
static int cuk[5001];

int main(){
    int n;
    scanf("%i", &n);

    for(int i = 1; i <= n; ++i){
        scanf("%i", cuk + i);
    }

    sort(cuk + 1, cuk + n + 1);

    tab[0][0] = 1;

    const int M = cuk[n];

    for(int i = 1; i <= n; ++i){
        for(int j = 0; j < M; ++j){
            tab[i][j] = tab[i-1][j];

            if(j >= 2 * cuk[i] - 1){
                tab[i][j] = (tab[i][j] + tab[i-1][j - cuk[i]]) % P;
            }
        }
        tab[i][M] = tab[i-1][M];
        int pocz = max(M - cuk[i], cuk[i] - 1);

        for(int j = pocz; j <= M; ++j){
            tab[i][M] = (tab[i][M] + tab[i-1][j]) % P;
        }

    }

    int sum = 0;

    for(int i = 1; i <= M; ++i){
        sum = (sum + tab[n][i]) % P;
    }

    printf("%i\n", sum);
}