Clone

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other)
Total Submission(s) : 8   Accepted Submission(s) : 5

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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
题意:
   给出每个羊有n个属性,对于A羊B羊,如果所有i(1<=i<=n) A[i]>=B[i] 则B羊能存活,问你最多能有几只羊同时存活
题解:
  所有存活的情况的羊的都能划分为属性和相同的情况
  dp[i][j]表示前i只羊属性总和为j的方案数

可以发现sum = 0 和 sum = 求和的方案数是一样的。

同理sum其实是对称的,和组合数一样。所以dp[n][sum / 2] 是最大的。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
using namespace std ;
typedef long long ll;
#define mod 1000000007
#define inf 100000
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//******************************************************************
int T,n,a[];
int dp[][];
int main()
{
scanf("%d",&T);
while(T--){
scanf("%d",&n);
int sum=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
memset(dp,,sizeof(dp));
for(int i=;i<=a[];i++)
{
dp[][i]=;
}
for(int i=;i<=n;i++)
{
for(int j=;j<=sum;j++)
{
for(int k=;k<=a[i]&&j+k<=sum;k++)
{
dp[i][j+k]=(dp[i][j+k]+dp[i-][j])%mod;
}
}
}
cout<<dp[n][sum/]<<endl;
}
return ;
}

代码

HDU 5000 2014 ACM/ICPC Asia Regional Anshan Online DP的更多相关文章

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

  2. HDU 5002 Tree(动态树LCT)(2014 ACM/ICPC Asia Regional Anshan Online)

    Problem Description You are given a tree with N nodes which are numbered by integers 1..N. Each node ...

  3. 2014 ACM/ICPC Asia Regional Anshan Online

    默默的签到 Osu! http://acm.hdu.edu.cn/showproblem.php?pid=5003 #include<cstdio> #include<algorit ...

  4. hdu 5016 点分治(2014 ACM/ICPC Asia Regional Xi'an Online)

    Mart Master II Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  5. hdu 5868 2016 ACM/ICPC Asia Regional Dalian Online 1001 (burnside引理 polya定理)

    Different Circle Permutation Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K ...

  6. HDU 5029 Relief grain(离线+线段树+启发式合并)(2014 ACM/ICPC Asia Regional Guangzhou Online)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5029 Problem Description The soil is cracking up beca ...

  7. HDU 5010 Get the Nut(2014 ACM/ICPC Asia Regional Xi'an Online)

    思路:广搜, 因为空格加上动物最多只有32个那么对这32个进行编号,就能可以用一个数字来表示状态了,因为只有 ‘P’   'S' 'M' '.' 那么就可以用4进制刚好可以用64位表示. 接下去每次就 ...

  8. 2014 ACM/ICPC Asia Regional Xi'an Online(HDU 5007 ~ HDU 5017)

    题目链接 A题:(字符串查找,水题) 题意 :输入字符串,如果字符串中包含“ Apple”, “iPhone”, “iPod”, “iPad” 就输出 “MAI MAI MAI!”,如果出现 “Son ...

  9. HDU 5052 Yaoge’s maximum profit 光秃秃的树链拆分 2014 ACM/ICPC Asia Regional Shanghai Online

    意甲冠军: 特定n小点的树权. 以下n每一行给出了正确的一点点来表达一个销售点每只鸡价格的格 以下n-1行给出了树的侧 以下Q操作 Q行 u, v, val 从u走v,程中能够买一个鸡腿,然后到后面卖 ...

随机推荐

  1. GCC编译链接过程

    编译链接过程 代码 #cat main.c #include <stdio.h> int add(int x, int y); int sub(int x, int y); int mul ...

  2. JVM优化(下)

    14.Tomcat8优化之G1牢记收集器的测试结果以及小结: jmeter测试:(1)tomcat未做任何优化:(2)禁用AJP:(3)启用连接池:(4)设置最大线程数1000,初始线程数200:(5 ...

  3. XP禁用了U盘和移动硬盘方法

    会不会是你XP禁用了U盘和移动硬盘下面这些是任何禁用U盘的!你自己反着试下嘛!方法一,BIOS设置法(快刀斩乱麻法) 进入BIOS设置,选择“Integrated Peripherals”选项,展开后 ...

  4. Git中文书籍

    Git中文书籍: http://git-scm.com/book/zh/v1

  5. socket编程(Java实现)

    主要是前段时间学习的网络知识的基于TCP与UDP编程,Java实现简单的大小写字母的转化,该文主要参考: https://blog.csdn.net/yjp19871013/article/detai ...

  6. 六、面向切面的spring(2)

    这个是承接五的,这部分主要的内容是在XML中声明切面. 一.在XML中声明切面 让我们先看一下spring中的AOP配置元素有哪些: AOP配置元素 用途 <aop:advisor> 定义 ...

  7. python爬取网页图片

    # html:网页地址 def getImg2(html): soup = BeautifulSoup(html, 'html.parser') href_regex = re.compile(r'^ ...

  8. Python学习笔记(1)——Python的概述(Python的环境、变量、数据类型、基本运算)

    Table of Contents 1. Python概述 1.1. Python基础知识 1.2. 运行环境 1.3. Python的格式 1.4. Python的变量. 2. Python的数据类 ...

  9. 虚拟机Linux与本地虚拟网卡配置---NAT链接方式

    虚拟机Linux与本地虚拟网卡配置---NAT链接方式 **********这是我亲自尝试多次实践出来的结果,不是复制粘贴************************* 首先进行初始化,这样避免有 ...

  10. 基础知识:if条件、while循环、for循环 相关练习

    1.实现用户输入用户名和密码,当用户名为 seven 且 密码为 123 时,显示登陆成功,否则登陆失败! while True: name = input('请输入用户名:') psw = inpu ...