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
#include <bits/stdc++.h>
#include <iostream>

using namespace std;
const int MOD = 1000000007;
int n;
int tab[5002];
long long score[5002], nextt[5002];
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> tab[i];
    }
    sort(tab + 1, tab + n + 1);
    if (tab[1] > 1) {
        cout << 0 << endl;
        return 0;
    }
    score[0] = 1;
    score[1] = 1;
    for (int i = 2; i <= n; i++) {
        for (int j = tab[i]-1; j <= 4999; j++) {
            nextt[min(j + tab[i], 4999)] += score[j];
            nextt[min(j + tab[i], 4999)] %= MOD;
        }
        for (int j = 1; j <= 4999; j++) {
            score[j] += nextt[j];
            score[j] %= MOD;
            nextt[j] = 0;
        }        
    }
    long long counter = 0;
    for (int i = 1; i <= 4999; i++) {
        counter += score[i];
        counter %= MOD;
    }
    cout << counter << endl;
    return 0;
}