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
52
53
54
55
56
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 5005;

const ll mod = (int) (1e9 + 7);

int tab[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> tab[i];

    sort(tab, tab + n);

    map<int, ll> M;
    M[0] = 1;
    vector<pair<int, ll> > V;

    ll res = 0;
    for (int i = 0; i < n; i++) {
        V.clear();
        for (auto& x : M) {
            if (tab[i] <= x.fi + 1) {
                res = (res + x.se) % mod;

                int t = x.fi + tab[i];
                if (t >= 5000)
                    t = 5000;

                V.push_back({t, x.se});
            }
            //cout << "[" << x.fi << " " << x.se << "] ";
        }
        //cout << endl;

        for(auto x : V)
            M[x.fi] = (M[x.fi] + x.se) % mod;
    }

    cout << res << "\n";

    return 0;
}