HDOJ 5000 Clone

所有满足的情况的属性和是一定的,而且属性和等于sum/2时得到的结果最大.

Clone

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 574    Accepted Submission(s): 277

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

Source

2014 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;
}
时间: 2024-08-06 10:53:31

HDOJ 5000 Clone的相关文章

HDU 5000 Clone(鞍山网络赛D题)

HDU 5000 Clone 这场就出了3题..就坑在这题上了,还好保住了名额 思路:要推出最大值的时候,每个人的属性和必然相同,并且这个和必然是所有和 / 2,这样的话,问题转化为给n个数字,要组合成sum / 2有多少种方法,就用dp背包推一遍就可以得解了. 现场的时候就没推出sum / 2就是答案 代码: #include <cstdio> #include <cstring> const int MOD = 1000000007; const int N = 2005; i

HDU 5000 Clone(瞎搞)

题目地址:HDU 5000 这个题当时有过这种想法,就是所有满足的情况的属性和是一定的.但是不会求方案数..(太弱...)而且当时也很不确定猜测是否正确..所以就放下了...算是通过学习了下dp求方案数吧. 至于那个猜测,我也给不出证明,但是个人觉得是只有在和都是相等的时候,才可以通过某一个数的增减来始终保持至少有一个较大的,至少有一个较小的,而假如和不一样的话,就会产生其中一个会消灭另一个的情况.所以就转换成了和是多少的情况下方案数最大.很明显能够猜的出来是和的一半的时候(同样不会证明...看

HDU 5000 Clone(离散数学+DP)(2014 ACM/ICPC Asia Regional Anshan Online)

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

hdu 5000 Clone (dp + 找规律)

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 righ

hdu 5000 Clone

dp,用dp[i][j],表示和为i的前j个维度的种类.其中arr[i],表示第i维的最大值. 则\begin{equation} dp[i][j] = \sum_{0 \leq k \leq \min(i,arr[i])} dp[i-k][j-1] \end{equation} 最后取和为sum/2的种类即可.原因可参照投n次投骰子,求骰子和的为多少时,概率最大. 代码如下: 1 #define MOD 1000000007 2 #define MAXN 2002 3 #include <cs

HDU 5000 Clone 规律+dp 2014 ACM/ICPC Asia Regional Anshan Online

每只羊有n个属性 下面n个数字表示每个属性的值范围为[ 0, T[i] ] 对于羊圈里的a羊和b羊,若a羊的每个属性都>=b羊,则a羊会杀死b羊. 问羊圈里最多存活多少只羊. 规律1:sum相同的羊不会互相杀死. 因为若2个羊的属性都相同,a羊某个属性要增加1,则a羊另一个属性要减少1,这样ab一定能共存. 规律2: sum不同的羊不会重合. 我们设a羊sum = x,b羊sum = y,若a,b羊能共存,但不会把ab同时放到羊圈里. 因为一定存在一只羊c ,sum = x,且c和b不能共存,既

Java clone() 浅克隆与深度克隆

内容转自:http://www.blogjava.net/orangelizq/archive/2007/10/17/153573.html 现在Clone已经不是一个新鲜词语了,伴随着“多莉”的产生这个词语确实很“火”过一阵子,在java中也有这么一个概念,它可以让我们很方便的“制造”出一个对象的副本来,下面来具体看看java中的Clone机制是如何工作的?     1. Clone&Copy     假设现在有一个Employee对象,Employee tobby =new Employee

HDOJ 3376 Matrix Again

和HDOJ 2686 一样,只是范围不同 最大费用最大流..... 与最小费用最大流的区别用////////////标出来了 对于detour,在源点和汇点处的边的流量为2 对于每个点只能经过一次,拆点,两个点直接建一条流量为1,费用为mp[i][j]的边 对于每个点可以走到他的左边和下边:连一个费用为0流量大于1的边 Matrix Again Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 102400/102400 K (Jav

hdoj 1824 Let&#39;s go home(2-SAT)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1824 思路分析:该问题为2-SAT问题:需要注意逻辑推理的等价性: (1)题目第一个条件:每一个队或者队长留下或者其与两名队员同时留下,或者表明只能为两种情况中的一种:假设三人为A,B,C,队长为A,0表示不留下,1表示留下,因为B与C同时留下或者不留下,只要B,C中其中一个没有留下或者留下,则B,C中另一个也同样留下或者不留下,所以可以从该条件中推导出六条等价关系,即A不留下->B,C同时留下,A