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

const int N = 5000 + 10, mod = 1e9 + 7;

int a[N], dp[2][N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  std::sort(a, a + n);
  dp[0][0] = 1;
  for (int i = 0; i < n; ++i) {
    int *u = dp[i & 1], *v = dp[(i & 1) ^ 1];
    for (int j = 0; j < N; ++j) v[j] = u[j];
    for (int j = a[i] - 1; j < N; ++j) if (u[j]) {
      int k = std::min(j + a[i], N - 1);
      if ((v[k] += u[j]) >= mod) v[k] -= mod;
    }
  }
  int ret = 0;
  for (int i = 1; i < N; ++i) {
    if ((ret += dp[n & 1][i]) >= mod) ret -= mod;
  }
  printf("%d\n", ret);
  return 0;
}