zoukankan      html  css  js  c++  java
  • 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
     



    #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
    ",dp[(n-1)%2][sum/2]);
        }
        return 0;
    }
    



    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    Docker学习笔记之一,搭建一个JAVA Tomcat运行环境
    利用Docker构建开发环境
    MyEclipse 8.6.1 制作绿色版
    Tomcat,JBoss与JBoss Web
    oracle,mysql,SqlServer三种数据库的分页查询
    Tomcat+JSP经典配置实例
    [转载]JDK自带的实用工具——native2ascii.exe
    用sql删除数据库重复的数据的方法
    Dom4j 使用简介(全而好的文章)
    Java操作XML文件 dom4j 篇
  • 原文地址:https://www.cnblogs.com/yxwkf/p/4658958.html
Copyright © 2011-2022 走看看