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

using namespace std;

int a[5000];
long long int t[2][5000];
int curr = 0;
int main()
{
    int n;
    cin >> n;
    for(int i=0; i<n; ++i)
    {
        cin >> a[i];
    }
    sort(a,a+n);

    t[curr][0] = 1;
    if(a[0]!=1)
    {
        cout << 0;
        return 0;
    }
    t[curr][1] = 1;

    const long long int mod = 1'000'000'007;
    for(int i=1; i<n; ++i)
    {
        copy(t[curr], t[curr]+5000, t[1-curr]);
        for(int j=a[i]-1; j<5000; ++j)
        {
            t[1-curr][min(j+a[i],4999)] += t[curr][j];
            t[1-curr][min(j+a[i],4999)] %= mod;
        }
        curr = 1-curr;
    }

    long long int sum = -1;
    for(int i=0; i<5000; ++i)
    {
        sum += t[curr][i];
    }

    sum %= mod;

    cout << sum;

    return 0;
}