HDOJ 5000 Clone

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   io   os   java   ar   

 所有滿足的情況的屬性和是一定的,而且屬性和等於sum/2時得到的結果最大.


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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.