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

using namespace std;
 
int main()
{
    int n, a;
    scanf("%d",&n);
    vector<int> v;
    for (int i=0; i<n; i++)
    {
        scanf("%d",&a);
        v.push_back(a);
    }
    sort(v.begin(), v.end());

    if (v[0] != 1)
    {
        printf("0\n");
        return 0;
    }

    unordered_map<int, int> m1, m2;
    int mod = 1000;
    mod = mod*1000;
    mod = mod*1000;
    mod = mod+7;
    unordered_map<int, int>::iterator it;
    m1.reserve(50000);
    m2.reserve(50000);

    int result = 0;
    m1[v[0]] = 1;
    m2[v[0]] = 1;

    for (int i=1; i<n; i++)
    {
        //cout << "v[i]: " << v[i] << endl;
        //m2.clear();

        if (v[i] == 1)
            m2[1]++;

        for ( it = m1.begin(); it != m1.end(); it++ )
        {
            //cout << it->first << ":" << it->second << " ";
            if (it->first >= v[i]-1)
            {
                //if (m2.find(it->first+v[i]) == m2.end())
                //    m2[it->first+v[i]] = it->second;
                //else
                    m2[it->first+v[i]] = (m2[it->first+v[i]] + it->second ) % mod;
                    
            }
            else
            {
                //result = (result + it->second) % mod;
                result = (result + it->second) % mod;
                m2.erase(it->first);
            }
        }
        //cout << endl;
        //cout << "result: " << result << endl;
        m1 = m2;
    }
    for ( it = m1.begin(); it != m1.end(); it++ )
    {
        //cout << it->first << ":" << it->second << " ";
        result = (result + it->second) % mod;
    }

    printf("%d\n",result);

}