hdu 5000 Clone 2014 ACM/ICPC Asia Regional Anshan Online

来源:互联网 发布:office mac破解版迅雷 编辑:程序博客网 时间:2024/04/29 03:44

Clone

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 447    Accepted Submission(s): 215


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.
 

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]. 
 

Output
For each test case, output an integer representing the answer MOD 10^9 + 7.
 

Sample Input
21528 6
 

Sample Output
17
 

Source
2014 ACM/ICPC Asia Regional Anshan Online
 

Recommend
hujie   |   We have carefully selected several similar problems for you:  5017 5016 5015 5013 5012 
 

题意:一个克隆人有n个属性,如果一个克隆人的任何一个属性都不大于另一个,他就不应该存在,给你n和每个属性的最大值,问最多能有多少克隆人存在。

思路:如果说能保证最多的克隆人存在,那么他们的属性和一定相等,且为所有最大属性和的一半。(好像很有道理,却说不出来哪有道理的结论)。比赛的时候神犇推得出来背包一下就过掉了,我这样的小菜做这种题只能靠yy了。知道结论直接01背包求能到达sum/2的所有情况就好了。

#include <iostream>#include <stdio.h>#include <cmath>#include <cstring>#include <algorithm>using namespace std;const int mod=1e9+7;const int N=2005;int dp[N*N/2],a[N];int main(){    int n,t,sum;    scanf("%d",&t);    while(t--){        scanf("%d",&n);        sum=0;        for(int i=0;i<n;i++){            scanf("%d",&a[i]);            sum+=a[i];        }        sum/=2;        memset(dp,0,sizeof(dp));        dp[0]=1;        for(int i=0;i<n;i++){            for(int j=sum;j>=0;j--){                for(int k=1;k<=a[i]&&k<=j;k++)                 dp[j]=(1ll*dp[j]+dp[j-k])%mod;            }        }        printf("%d\n",dp[sum]);    }    return 0;}



0 0
原创粉丝点击