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
#include <bits/stdc++.h>
using namespace std;

const int M = 1e9 + 7;
int n, w;
int t[5007], dp[5007];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    sort(t, t + n);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        dp[5001] *= 2;
        dp[5001] %= M;
        for (int j = 5000; j >= t[i] - 1; j--) {
            if (j + t[i] > 5000) {
                dp[5001] += dp[j];
                dp[5001] %= M;
            } else {
                dp[j + t[i]] += dp[j];
                dp[j + t[i]] %= M;
            }
        }
    }
    for (int i = 1; i <= 5001; i++) {
        w += dp[i];
        w %= M;
    }
    cout << w;
    return 0;
}