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

using namespace std;

const int mod = 1e9 + 7, max_x = 20e6 + 5;

int dp[max_x], tab[5005];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, max_w = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> tab[i];
    sort(tab, tab + n);
    dp[0] = 1;
    for (int i = 0; i < n; i++){
        for (int j = max_w; j >= tab[i] - 1; j--){
            if (dp[j]){
                max_w = max(max_w, j + tab[i]);
                dp[j + tab[i]] += dp[j];
            }
        }
    }
    long long wynik = 0;
    for (int i = 1; i <= max_w; i++)
        wynik = (wynik + dp[i]) % mod;
    cout << wynik << "\n";
    return 0;
}