The sum of all the attributes that meet the condition is certain, and the sum of the sum and the sum is equal to sum/2, the maximum result is obtained.
Clone
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/65536 K (Java/Others)
Total submission (s): 574 accepted submission (s): 277
Problem descriptionafter eating food from Chernobyl, DRD got a super power: He cocould 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 cocould not keep ve. 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 cocould not keep ve.
Now, as DRD's friend, ATM wants to know how many clones can have ve at most.
Inputthe 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].
Outputfor each test case, output an integer representing the answer MOD 10 ^ 9 + 7.
Sample Input
21528 6
Sample output
17
Source2014 ACM/ICPC Asia Regional Anshan online
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long int LL;const LL mod=(1e9+7);int v[2020],n;LL sum,dp[2][2000400];int main(){ int T_T; scanf("%d",&T_T); while(T_T--) { scanf("%d",&n); sum=0; for(int i=0;i<n;i++) { scanf("%d",v+i); sum+=v[i]; } memset(dp,0,sizeof(dp)); for(int i=0;i<n;i++) { if(i==0) { for(int j=0;j<=v[i];j++) dp[0][j]=1; continue; } for(int j=0;j<=sum/2;j++) { int temp=0; for(int k=0;k<=v[i]&&k<=j;k++) { temp=(temp+dp[(i%2)^1][j-k])%mod; } dp[i%2][j]=temp; } } printf("%d\n",dp[(n-1)%2][sum/2]); } return 0;}
Hdoj 5000 clone