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.

题意:有许多克隆人,每个人都有 N 项属性,每个属性都有上限,每个克隆人的属性是 1 到 该属性上限的一个整数。现在如果有克隆人所有属性都小于等于另外某个克隆人,那么他就无法生存,问给定每个属性上限,最多有多少克隆人可以生存。

N范围2000,所有属性上限的总和范围也是2000。

其实最优的情况是所有克隆人属性总和都相等,那么一定有人在这个属性比较优,而其他的在另一个属性比较优,前提是没有两个人所有属性均相等。

那么问题其实就变成了如果我知道属性总和,有多少种不同的构成这个总和的方法?然后对于所有总和都求一遍,取一个最大值就可以了。

那么就变成了非常经典的DP思路,拆分数字。

DP[ i ][ j ] 表示选取完第 i 个数,总和是 j 的情况总数;

第 i 个数的取值范围是 1 ~ T[ i ],T[ i ] 是第 i 个属性的上限;

枚举这个数的取值是 k ,DP[ i ][ j ] = ∑ ( k:1~T[i] ) ( DP[ i-1 ][ j-k ] );

然后因为 j 是前一层中 j 较小的一部分的和,所以可以从后往前更新,压缩掉 i 这一维。

用大数写。

 import java.util.*;
import java.math.BigInteger;
public class Main {
static int t[]=new int[];
static BigInteger dp[]=new BigInteger[];
static BigInteger mmod = BigInteger.valueOf();
public static void main(String[] args){
Scanner input = new Scanner(System.in);
for(int i=;i<=;++i){
t[i]=;
dp[i]=BigInteger.ZERO;
}
int T=input.nextInt();
while(T--!=){
int n=input.nextInt();
int i=,sum=;
for(i=;i<=n;++i){
t[i]=input.nextInt();
sum+=t[i];
}
sum=sum*/;
for(i=;i<=;++i)dp[i]=BigInteger.ZERO;
BigInteger mx=BigInteger.ZERO;
dp[]=BigInteger.ONE;
for(i=;i<=n;++i){
for(int j=sum;j>;--j){
for(int k=;k<=t[i]&&j>=k;++k){
dp[j]=dp[j].add(dp[j-k]);
}
}
}
for(i=;i<=sum;++i){
if(mx.compareTo(dp[i])<)mx=dp[i];
}
mx=mx.mod(mmod);
System.out.println(mx);
}
input.close();
}
}

hdu5000 Clone dp+大数的更多相关文章

  1. hdu-5000 Clone(dp)

    题目链接: Clone Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Pro ...

  2. soj1166. Computer Transformat(dp + 大数相加)

    1166. Computer Transformat Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description A sequenc ...

  3. POJ 1625 Censored!(AC自动机->指针版+DP+大数)题解

    题目:给你n个字母,p个模式串,要你写一个长度为m的串,要求这个串不能包含模式串,问你这样的串最多能写几个 思路:dp+AC自动机应该能看出来,万万没想到这题还要加大数...orz 状态转移方程dp[ ...

  4. uva 10069 Distinct Subsequences 【dp+大数】

    题目:uva 10069 Distinct Subsequences 题意:给出一个子串 x 和母串 s .求子串在母串中的不同序列的个数? 分析:定义dp[i][j]:x 的前 i 个字母在 s 的 ...

  5. hdu5000 背包dp

    题意可抽象为:N个包中每个包容量是T[i],每个包都拿一些,设拿出的总数为sum时的方案数为q,求max(q) 设dp[i][j]为拿了前i个包,共拿出了j物品时的方案数.那么 for i=1 to ...

  6. HDU5000 (DP + 规律)

    题意:举例子好说点,告诉你4个数字,8,6,4,2四个数字,组成一个四位数,如果两个数字分别是1111,2222,则2222会吧1111杀掉,就是组成的四位数不能每一位都小于或等于一个数,然后让你求出 ...

  7. URAL 1158 AC自动机上的简单DP+大数

    题目大意 在一种语言中的字母表中有N(N<=50)个字母,每个单词都由M(M<=50)个字母构成,因此,一共可以形成N^M个单词.但是有P(P<=10)个串是被禁止的,也就是说,任何 ...

  8. HDU 5568 sequence2 区间dp+大数

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5568 题意: 求所有长度为k的严格升序子序列的个数. 题解: 令dp[i][k]表示以i结尾的长度为 ...

  9. HDU1502 Regular Words DP+大数

    要是c语言可以和java一样写大数就好了,或者我会写重载就好了,最后还是只能暴力一把. 开始写的记忆化搜索,然而n=10就超过LL了 #include<cstdio> #include&l ...

随机推荐

  1. EPEL源-是什么全称

    EPEL源   EPEL (Extra Packages for Enterprise Linux)是基于Fedora的一个项目,为“红帽系”的操作系统提供额外的软件包,适用于RHEL.CentOS和 ...

  2. cumsum函数

    >>> a = np.array([[1,2,3], [4,5,6]]) >>> a array([[1, 2, 3], [4, 5, 6]]) >>& ...

  3. Java集合框架源码分析(2)LinkedList

    链表(LinkedList) 数组(array)和数组列表(ArrayList)都有一个重大的缺陷: 从数组的中间位置删除一个元素要付出很大的代价,因为数组中在被删除元素之后的所有元素都要向数组的前端 ...

  4. conda基本操作

    准备环境 # 下载并安装conda基础环境 $ wget https://mirror.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-4.3.1 ...

  5. git项目远程地址修改后本地如何处理

    今天运维人员为了方便管理,将远程的项目地址给迁移了, 原来是 git@git.lalala.com:yuanlaide/happy.git 变成了 git@git.lalala.com:houlaid ...

  6. selenium java 文件上传、下载

    1.webdriver对页面文件的下载 我们一般操作浏览器下载时会让我们选择下载的目录然后经过一系列操作后才进行文件下载操作,但是用webdriver不能按这样的方式操作.经过查询资料找到了如下的实现 ...

  7. sql 同一个字段在查询结果中出现两次

    SELECT GET .daytime,    GET.data AS GET,    xh.data AS xh FROM    ( SELECT daytime, SUM ( get_sum ) ...

  8. jQuery获取包括当前元素的HTML

    1.获取当前元素内的HTML (1)方法一 $("#current").html(); (2)方法二 document.getElementById("current&q ...

  9. Win10系列:C#应用控件基础6

    RadioButton控件 在应用程序的开发过程中开发者经常使用多个RadioButton控件来显示一组单选按钮,仅允许用户从中选择一项.RadioButton控件和CheckBox控件的差别在于,用 ...

  10. firewall-cmd.man

    FIREWALL-CMD(1) firewall-cmd FIREWALL-CMD(1) NAME firewall-cmd - firewalld command line client SYNOP ...