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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 5005
#define P 1000000007
typedef long long ll;
int A[MAX];
ll S[MAX*MAX];

int cmpint(const void *av, const void *bv) {
    int a = *(int *)av;
    int b = *(int *)bv;
    return a-b;
}


int main()
{
    int n, i;

    scanf("%d", &n);
    for (i=0; i<n; i++) {
        scanf("%d", &A[i]);
    }
    qsort(A, n, sizeof(A[0]), cmpint);
    memset(S, 0, sizeof(S));

    ll s = 0;
    S[0] = 1;
    for (i=0; i<n; i++) {
        if (A[i] > s+1) break;
        for (int j=s; j>=A[i]-1; j--) {
            S[j+A[i]] = (S[j+A[i]] + S[j]) % P;
        }
        s += A[i];
    }

    ll ss = 0;
    for (i=1; i<=s; i++) {
        ss = (ss + S[i]) % P;
    }

    printf("%lld\n", ss);

    return 0;
}