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

using namespace std;

const int mod = 1000000007;

int main()
{
    int n;
    int a[5001];
    
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    
    sort(a + 1, a + n + 1);
    
    int limit = 5000;
    
    int dp[limit][2] = {};
    int upper[2] = {};
    
    dp[0][0] = 1;
    
    for (int i = 1; i <= n; i++)
    {
        int curr = i % 2;
        int prev = 1 - curr;
        
        for (int j = 0; j < 2 * a[i] - 1 && j < limit; j++)
            dp[j][curr] = dp[j][prev];
        
        for (int j = 2 * a[i] - 1; j < limit; j++)
            dp[j][curr] = (dp[j][prev] + dp[j - a[i]][prev]) % mod;
        
        upper[curr] = (2 * upper[prev]) % mod;
        for (int j = 1; j <= a[i]; j++)
            if (limit - j + 1 >= a[i])
                upper[curr] = (upper[curr] + dp[limit - j][prev]) % mod;
    }
    
    int last = n % 2;
    int answer = upper[last];
    
    for (int j = 1; j < limit; j++)
        answer = (answer + dp[j][last]) % mod;
    
    cout << answer << endl;
    
    return 0;
}