http://acm.hdu.edu.cn/showproblem.php?pid=5000
Problem Description
After eating food from Chernobyl, DRD got a super power: he could clone himself right now! He used this power for several times. He found out that this power was not as perfect as he wanted. For example, some of the cloned objects were tall, while some were short; some of them were fat, and some were thin.
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.
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.
Input
The first line contains an integer T, denoting the number of the test cases.
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].
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].
Output
For each test case, output an integer representing the answer MOD 10^9 + 7.
Sample Input
2 1 5 2 8 6
Sample Output
1 7
/**
题意:有n种属性,每种属性的数值可以是0-T[i],当一个人属性全部小于等于另一个人的属性时,
小的那个人会被淘汰,问最多同时存在多少人
解法:sum表示一个人的属性和。首先,人数最多的情况下这些人的sum是相同的,因为这种情况下一个属
性减少另一个属性必然增加,保证满足条件。其次发现,sum=0的方案数和sum=ΣT[i]的方案数相同,
因此在sum=(ΣT[i])/2取得最大值.这样问题转化为n个数,每个数可以取0-T[i],和为(ΣT[i])/2的方案数。
dp[i][j]表示选到第i个人时,属性和为j的种数
*/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int MOD=1e9+7;
int T[2003],dp[2003][2000];
int n;
int main()
{
int TT;
scanf("%d",&TT);
while(TT--)
{
scanf("%d",&n);
int sum=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&T[i]);
sum+=T[i];
}
sum>>=1;
memset(dp,0,sizeof(dp));
for(int i=0 ;i<=T[1] ;i++)
dp[1][i]=1;
for(int i=2;i<=n;i++)
{
for(int j=0;j<=sum;j++)
{
for(int k=0;k<=T[i]&&k<=j;k++)
{
dp[i][j]=(dp[i][j]+dp[i-1][j-k])%MOD;
}
}
}
printf("%d\n",dp[n][sum]);
}
return 0;
}