More evidence showed that for two clones A and B, if A was no worse than B in all fields, then B could not survive. More specifically, DRD used a vector v to represent each of his clones. The vector v has n dimensions, representing a clone having N abilities. For the i-th dimension, v[i] is an integer between 0 and T[i], where 0 is the worst and T[i] is the best. For two clones A and B, whose corresponding vectors were p and q, if for 1 <= i <= N, p[i] >= q[i], then B could not survive.
Now, as DRD's friend, ATM wants to know how many clones can survive at most.
For each test case: The first line contains 1 integer N, 1 <= N <= 2000. The second line contains N integers indicating T[1], T[2], ..., T[N]. It guarantees that the sum of T[i] in each test case is no more than 2000 and 1 <= T[i].
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <functional>
using namespace std;
typedef long long LL; const int MAXN = ;
const int MOD = 1e9 + ; void update_add(int &a, int b) {
a += b;
if(a >= MOD) a -= MOD;
} int a[MAXN][MAXN], sum[MAXN][MAXN];
int b[MAXN];
int n, s, T; void solve() {
memset(a, , sizeof(a));
s = accumulate(b, b + n, ); for(int i = ; i <= b[]; ++i) a[][i] = ;
sum[][] = a[][];
for(int j = ; j <= s; ++j) sum[][j] = (sum[][j - ] + a[][j]) % MOD; for(int i = ; i < n; ++i) {
for(int j = ; j <= s; ++j) {
//for(int k = j - b[i]; k <= j; ++k) a[i][j] += a[i - 1][k];
if(j - b[i] <= ) a[i][j] = sum[i - ][j];
else a[i][j] = (sum[i - ][j] - sum[i - ][j - b[i] - ] + MOD) % MOD;
}
sum[i][] = a[i][];
for(int j = ; j <= s; ++j) sum[i][j] = (sum[i][j - ] + a[i][j]) % MOD;
}
} void print() {
for(int j = ; j <= s; ++j)
printf("%4d", j);
puts("");
for(int i = ; i < n; ++i) {
for(int j = ; j <= s; ++j)
printf("%4d", a[i][j]);
puts("");
}
} int main() {
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
for(int i = ; i < n; ++i) scanf("%d", &b[i]);
sort(b, b + n);
solve();
//print();
printf("%d\n", a[n - ][s / ]);
}
}