码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5000 Clone (dp + 找规律)

时间:2014-11-11 14:28:12      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:des   style   io   color   ar   os   java   sp   for   

Clone

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


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
2 1 5 2 8 6
 

Sample Output
1 7
 


题意:每只羊有n个属性,下面n个数字表示每个属性的值范围为[ 0, T[i] ]对于羊圈里的a羊

和b羊,若a羊的每个属性都>=b羊,则a羊会杀死b羊。问羊圈里最多存活多少只羊。

思路:要推出最大值的时候,每个人的属性和必然相同,并且这个和必然是所有和 / 2,这

样的话,问题转化为给n个数字,要组合成sum / 2有多少种方法,就用dp背包推一遍就可

以得解了。



#include <iostream>
#include <cstdio>
#include <cstring>
#define LL long long
using namespace std;
const LL mod=1000000007;
const int maxn=2010;

int a[maxn],sum,n;
LL dp[maxn];

void input()
{
    scanf("%d",&n);
    sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    sum/=2;
}

void solve()
{
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(int i=1;i<=n;i++)
        for(int k=sum;k>=1;k--)
            for(int j=1;j<=a[i];j++)
                if(k-j>=0)
                    dp[k]=(dp[k]+dp[k-j])%mod;
    printf("%I64d\n",dp[sum]);
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
         input();
         solve();
    }
    return 0;
}



hdu 5000 Clone (dp + 找规律)

标签:des   style   io   color   ar   os   java   sp   for   

原文地址:http://blog.csdn.net/u012596172/article/details/41010161

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!