HDOJ 5000 Clone

HDOJ 5000 Clone

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

  所有的属性,以满足一定的条件,是,财产和等于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\n",dp[(n-1)%2][sum/2]);
    }
    return 0;
}

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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/117495.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 汇编语言实现数组求和_汇编语言loop循环1到100求和

    汇编语言实现数组求和_汇编语言loop循环1到100求和ARM汇编数组求和、ARM汇编语句循环框架

    2022年10月2日
    2
  • python实现 猴子摘香蕉「建议收藏」

    python实现 猴子摘香蕉「建议收藏」#猴子摘香蕉importsys#找到箱子defmove():globaliwhileTrue:a_1=input(“输入你下步走的地方:”)whileTrue:ifa_1==b:i+=1print(‘找到箱子,通过第一关,进入第二关’)push()else:.

    2022年9月26日
    2
  • python json 编码_python乱码转中文

    python json 编码_python乱码转中文python2.x版本的字符编码有时让人很头疼,遇到问题,网上方法可以解决错误,但对原理还是一知半解,本文主要介绍python中字符串处理的原理,附带解决json文件输出时,显示中文而非un

    2022年8月1日
    8
  • 数据库查询语句中的排序函数_数据库按照升序排列的语句

    数据库查询语句中的排序函数_数据库按照升序排列的语句1.排序查询语法排序查询语法:select*from表名orderby列1asc|desc[,列2asc|desc,…]语法说明:先按照列1进行排序,如果列1的值相同,则按照列2排序,以此类推asc从小到大排序,即升序desc从大到小排序,即降序默认按照从小到大排序(即asc关键字)举例:–查询未删除男生信息,按学号降序select*fromstudentswhereis_del=0andgender=’男’orderbyid

    2025年10月3日
    2
  • 从零开始学android编程之Toast提示信息框「建议收藏」

    从零开始学android编程之Toast提示信息框「建议收藏」Toast类可以在程序界面上显示一个简单的提示信息,这个提示信息框用于向用户生成简单的提示信息。1创建包含信息的提示框通过Toast类的静态方法makeText()创建信息提示框,该提示框中包含了指定的信息。该方法的格式为publicstaticToastmakeText(Contextcontext,CharSequencetext,intduration);其

    2022年6月10日
    56
  • 对象转json忽略空参「建议收藏」

    对象转json忽略空参「建议收藏」有时候我们在传json的时候需要过滤掉那些数据为空的参数,我们可以这样:JsonUtil.object2JSON(request,SerializerFeature.WriteDateUseDateFormat); 当然,也可以这样:JSON.toJSONString(request)这两种方式都需要添加阿里的jar包&lt;dependency&gt; &lt;gr…

    2025年12月5日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号