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
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define ull unsigned long long
#define MAX_A 5000
#define MOD 1000000007
//a*n -> maks cuk razem -> 25 000 000

using namespace std;

int main() {
    int n, a;

    scanf("%d", &n);

    int *packs = new int[n]();
    ull *options = new ull[n*MAX_A]();

    for(int i=0; i<n; i++) {
        scanf("%d", packs+i);
    }

    sort(packs, packs+n);

    if(packs[0] != 1) {
        printf("0");
        return 0;
    }

    options[0] = 1;
    options[1] = 1;
    int pack, max_sum = 1, last_covered = 1;

    for(int i=1; i<n; i++) {
        pack = packs[i];
        if(last_covered >= pack-1) {
            last_covered = last_covered+pack;

            int k = max_sum;
            while(k >= pack-1) {
                options[k+pack] += options[k];
                k--;
            }
            max_sum += pack;
        }
        else {
            break;
        }
    }

    ull res = 0;

    for(int i=1; i<=max_sum; i++) {
        res += options[i];
    }

    printf("%d", (int)(res%MOD));

    delete [] packs;
    delete [] options;

    return 0;
}