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
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

ll dp[5005];
ll tab[5005];
int n, maxv, toop;
ll res;
const ll mod = 1000000007;

int main()
{
    scanf("%d", &n);
    for(int i = 1; i<=n; i++)
    {
        scanf("%lld", &tab[i]);
        toop = max(toop, (int)tab[i]);
    }
    sort(tab + 1, tab + n + 1);
    dp[0] = 1;
    maxv = 0;
    for(int i = 1; i<=n; i++)
    {
        for(int m = maxv; m>=tab[i] - 1; m--)
        {
            int temp = min((int)(m + tab[i]), toop);
            if(dp[m] > 0)
            {
                
                dp[temp]+=dp[m];
                dp[temp]%=mod;
                maxv = max(maxv, min(toop, temp));
            }
        }
        
    }
    for(int i = 1; i<=toop; i++)
    {
        res+=dp[i];
        res%=mod;
    }
    printf("%lld", res);
}