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

constexpr int MOD = 1e9 + 7;

int main() {
	int n;
	std::cin >> n;

	std::vector<int> candies(n);
	for (int i = 0; i < n; i++) {
		std::cin >> candies[i];
	}
	std::sort(candies.begin(), candies.end());

	std::vector<int> memo(5001);
	memo[0] = 1;
	for (auto c: candies) {
		std::vector<int> next_layer(5001, 0);
		for (int j = c - 1; j <= 5000; ++j) {
			int next = std::min(j + c, 5000);
			next_layer[next] += memo[j];
			next_layer[next] %= MOD;
		}
		for (int j = 0; j <= 5000; ++j) {
			memo[j] += next_layer[j];
			memo[j] %= MOD;
		}
	}

	long long result = 0;
	for (int i = 1; i <= 5000; ++i) {
		result += memo[i];
	}
	std::cout << (result % MOD) << '\n';
	return 0;
}