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

using namespace std;

const int MOD = 1000000007;

struct TestCase
{
  int package_count;
  vector<int> packages;
};

TestCase read_test_case();
void solve_test_case(TestCase);

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve_test_case(read_test_case());
}

TestCase read_test_case()
{
  TestCase test_case;
  cin >> test_case.package_count;
  test_case.packages.resize(test_case.package_count);
  for (auto& package : test_case.packages) cin >> package;
  return test_case;
}

void solve_test_case(TestCase test_case)
{
  sort(test_case.packages.begin(), test_case.packages.end());
  int max_el =
      *max_element(test_case.packages.begin(), test_case.packages.end());

  // A[p][c] -> Given first p elements, how many choices that sum to at least c
  vector<vector<int>> A;
  A.resize(test_case.package_count + 1);
  for (auto& v : A) v.resize(max_el + 1, 0);
  A[0][0] = 1;  // Base case, there is one choice for empty set

  for (int p = 0; p < test_case.package_count; p++)
  {
    for (int c = 0; c < max_el; c++)
    {
      int index = max(test_case.packages[p] - 1, c - test_case.packages[p]);

      A[p + 1][c] = (A[p][c] + A[p][index]) % MOD;
    }
  }
  cout << A[test_case.package_count][0] - 1 << "\n";
}