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
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <bits/stdc++.h>
using namespace std;

const int MAX_WARTOSC = 5000 + 2;
const int MAX_SUMA = MAX_WARTOSC + 10;
const int INF = 1e9 + 5;
const long long MOD = 1e9 + 7;

long long factorial[MAX_WARTOSC], inverse_factorial[MAX_WARTOSC], inverse_i[MAX_WARTOSC];

long long binomial_coefficient(int n, int k)
{
    return (((factorial[n] * inverse_factorial[k]) % MOD) * inverse_factorial[n - k]) % MOD;
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

    int n;
    cin >> n;

    vector <int> v(n);
    map <int, int> mapka;

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

        mapka[v[i]]++;
    }

    factorial[0] = 1;
    inverse_i[0] = 1;
    inverse_i[1] = 1;
    inverse_factorial[0] = 1;
    inverse_factorial[1] = 1;
    
    for(int i = 2; i < MAX_WARTOSC; i++)
    {
        inverse_i[i] = (MOD - (1LL * (MOD / i) * inverse_i[MOD % i]) % MOD) % MOD;
    }
    
    for(int i = 1; i < MAX_WARTOSC; i++)
    {
        factorial[i] = (1LL * factorial[i - 1] * i) % MOD;
        
        if(i > 1)
        {
			inverse_factorial[i] = (1LL * inverse_factorial[i - 1] * inverse_i[i]) % MOD;
		}
    }

    vector <int> dp(MAX_SUMA + 1, INF);

    dp[0] = 0;

    for(int i = 0; i < n; i++)
    {
        for(int j = MAX_SUMA; j >= 0; j--)
        {
            if(dp[j] != INF && j + v[i] <= MAX_SUMA)
            {
                dp[j + v[i]] = min(dp[j + v[i]], dp[j] + 1);
            }
        }
    }

    int za_duzy = MAX_SUMA;

    for(int i = 0; i < MAX_SUMA; i++)
    {
        if(dp[i] == INF)
        {
            za_duzy = i;
            break;
        }
    }

    long long ans = 0, suma = 0, poprzedni = 1;

    for(int i = 1; i < MAX_WARTOSC; i++)
    {
        if(i < za_duzy)
        {
            if(mapka.count(i))
            {
                for(int kombinacja = 1; kombinacja <= mapka[i]; kombinacja++)
                {
                    suma += binomial_coefficient(mapka[i], kombinacja);
                    suma %= MOD;
                }

                ans += (poprzedni * suma) % MOD;
				ans %= MOD;
				
                poprzedni = suma;
                suma = 0;
            }
        }

        else
        {
            break;
        }
    }

    cout << ans << "\n";
    return 0;
}