hdu5000 Clone dp+大数
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+大数的更多相关文章
- hdu-5000 Clone(dp)
题目链接: Clone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Pro ...
- soj1166. Computer Transformat(dp + 大数相加)
1166. Computer Transformat Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description A sequenc ...
- POJ 1625 Censored!(AC自动机->指针版+DP+大数)题解
题目:给你n个字母,p个模式串,要你写一个长度为m的串,要求这个串不能包含模式串,问你这样的串最多能写几个 思路:dp+AC自动机应该能看出来,万万没想到这题还要加大数...orz 状态转移方程dp[ ...
- uva 10069 Distinct Subsequences 【dp+大数】
题目:uva 10069 Distinct Subsequences 题意:给出一个子串 x 和母串 s .求子串在母串中的不同序列的个数? 分析:定义dp[i][j]:x 的前 i 个字母在 s 的 ...
- hdu5000 背包dp
题意可抽象为:N个包中每个包容量是T[i],每个包都拿一些,设拿出的总数为sum时的方案数为q,求max(q) 设dp[i][j]为拿了前i个包,共拿出了j物品时的方案数.那么 for i=1 to ...
- HDU5000 (DP + 规律)
题意:举例子好说点,告诉你4个数字,8,6,4,2四个数字,组成一个四位数,如果两个数字分别是1111,2222,则2222会吧1111杀掉,就是组成的四位数不能每一位都小于或等于一个数,然后让你求出 ...
- URAL 1158 AC自动机上的简单DP+大数
题目大意 在一种语言中的字母表中有N(N<=50)个字母,每个单词都由M(M<=50)个字母构成,因此,一共可以形成N^M个单词.但是有P(P<=10)个串是被禁止的,也就是说,任何 ...
- HDU 5568 sequence2 区间dp+大数
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5568 题意: 求所有长度为k的严格升序子序列的个数. 题解: 令dp[i][k]表示以i结尾的长度为 ...
- HDU1502 Regular Words DP+大数
要是c语言可以和java一样写大数就好了,或者我会写重载就好了,最后还是只能暴力一把. 开始写的记忆化搜索,然而n=10就超过LL了 #include<cstdio> #include&l ...
随机推荐
- wepy开发小程序eslint报错error 'getApp' is not defined no-undef
wepy开发小程序使用getApp().globalData保存全局数据很方便,但是会在控制台看到很多报错:“error 'getApp' is not defined no-undef”,这是esl ...
- CSS布局学习(二) - flex属性
flex属性 定义 flex布局包括最外层的容器和内部的元素,flex属性是内部元素属性.flex属性是flex-grow, flex-shrink, flex-basis三个属性的简写 flex-g ...
- HADOOP HA 踩坑 - 所有 namenode 都是standby
报错: 无明显报错 状况: 所有namenode都是standby,即ZK服务未生效 尝试一:手动强制转化某个namenode为active 操作:在某台namenode上,执行 hdfs haadm ...
- webpack引入eslint详解
- 服务列表中找不到mysql
服务列表中找不到mysql - 解决办法 1.在开始处输入cmd,找到cmd选择以管理员身份运行(必须以管理员运行,直接win+r打开无效) 2.进入到MySQL安装目录的bin目录 3.执行mysq ...
- linux常用命令 history命令
历史命令 history [选项] [历史命令保存文件] 选项 '-c' 清空历史命令 '-w' 把缓存中的历史命令写入历史命令保存文件~/.bash_history [root@ssgao1987 ...
- day15_python_1124
03序列化模块 04加密模块 05 os sys 模块 06 collections 模块 # 03 序列化模块 # 网络传输数据:字节 bytes# 文件写入内容:bytes , str # dic ...
- day062 中间件
中间件: 作用: 介于request和response之间的一到处理过程,相对比较轻量级,并且在全局上改变django的输入与输出,因为改变的是全局,所以需要谨慎使用,用不好会影响到性能. 当用户发 ...
- js生成指定范围的随机数
<!doctype html> <html lang="en"> <head> <meta http-equiv="Conten ...
- redis不重启,切换RDB备份到AOF备份
确保redis版本在2.2以上 [root@pyyuc /data ::]#redis-server -v Redis server v= sha=: malloc=jemalloc- bits= b ...