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
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    int n;

    long long int modulo = 1000000007;

    cin >> n;

    vector<int> a(n);

    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    sort(a.begin(), a.end());

    int MAX = 10001;

    vector<long long int> dp(MAX + 1);
    dp[0] = 1;

    long long int sum = 0;

    for (int i = 0; i < n; i++)
    {
        int offset = 1;

        int diff = max(0, - MAX + (2 * a[i] - 1));

        dp[MAX] *= 2; dp[MAX] %= modulo;

        while (offset + diff < a[i])
        {
            dp[MAX] += dp[MAX - offset]; dp[MAX] %= modulo;
            offset++;
        }

        for (int j = MAX - a[i]; j >= a[i] - 1; j--)
        { 
            dp[j + a[i]] += dp[j]; dp[j + a[i]] %= modulo;
        }

        for (int j = 1; j <= MAX; j++)
        {
            //cout << dp[j] << " ";
        }
        
        //cout << endl;
    }

    for (int i = 1; i <= MAX; i++)
    {
        sum += dp[i]; sum %= modulo;
    }

    cout << sum << endl;
}