【hdoj 5000】Clone

Clone
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1149 Accepted Submission(s): 535


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中能力,並且用能力值來衡量,當A在各個領域不比B差時,B不能生存。1~N領域的能力值爲0~T[i],判斷最多有多少克隆體共存。

解題思路: 當每個克隆體的屬性值總和爲所有最大值的和一半時克隆體共存最多。


code:

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


發佈了68 篇原創文章 · 獲贊 9 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章