
动态规划
文章平均质量分 91
lyhvoyage
不抛弃,不放弃!
展开
-
经典背包问题 01背包+完全背包+多重背包
01 背包有n 种不同的物品,每个物品有两个属性,size 体积,value 价值,现在给一个容量为 w 的背包,问最多可带走多少价值的物品。 int f[w+1]; //f[x] 表示背包容量为x 时的最大价值 for (int i=0; i for (int j=w; j>=size[i]; j--)原创 2013-04-06 20:27:01 · 31981 阅读 · 10 评论 -
NYOJ 1067 Compress String(区间dp)
Compress String时间限制:2000 ms | 内存限制:65535 KB难度:3描述One day,a beautiful girl ask LYH to help her complete a complicated task—using a new compression method similar to Run Length Encod原创 2014-08-09 17:14:46 · 1538 阅读 · 1 评论 -
hdu 4960 Another OCD Patient(dp)2014多校训练第9场
Another OCD Patient Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Problem Descri原创 2014-08-20 16:34:40 · 1841 阅读 · 0 评论 -
ZOJ 1642 Match for Bonus(dp)
Match for BonusTime Limit: 2 Seconds Memory Limit: 65536 KBRoy played a game with his roommates the other day. His roommates wrote 2 strings of characters, and gave each character a b原创 2014-08-02 18:16:44 · 1256 阅读 · 0 评论 -
hdu 4901 The Romantic Hero(计数dp)2014多校训练第4场1005
The Romantic Hero Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Problem De原创 2014-08-01 10:23:03 · 2699 阅读 · 1 评论 -
UVA 111 - History Grading(动态规划)
History Grading BackgroundMany problems in Computer Science involve maximizing some measure according to constraints.Consider a history exam in which students are asked to put severa原创 2013-07-30 14:14:20 · 2108 阅读 · 0 评论 -
NYOJ 716 River Crossing(动态规划)
River Crossing时间限制:1000 ms | 内存限制:65535 KB难度:4描述Afandi is herding N sheep across the expanses of grassland when he finds himself blocked by a river. A single raft is avail原创 2014-04-11 21:42:10 · 2139 阅读 · 0 评论 -
省赛组队赛5
#include#include#include#includeusing namespace std;const int N = 1e5 + 10;struct node{ __int64 x; __int64 y;}a[N];int next[N], dp[N];bool judge(node a0, node a1, node a2){ __i原创 2014-04-24 23:03:25 · 1034 阅读 · 0 评论 -
区间dp小结
区间dp,顾名思义,就是在区间上dp,即把整个区间划分为一个个的小区间,在小区间内dp求出最优值,然后把这些小区间合并以后就是整个取件的最优值。下面是一些比较经典的区间dp题目:1.NYOJ石子合并:http://acm.nyist.net/JudgeOnline/problem.php?pid=737题意:有n堆石子,每堆有a[i]个,每次合并时只能合并相邻的两堆,代价为两堆石子的个原创 2014-04-24 09:39:39 · 4745 阅读 · 0 评论 -
HDU 4502 吉哥系列故事——临时工计划(动态规划)
吉哥系列故事——临时工计划 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Problem D原创 2014-03-21 09:59:06 · 1461 阅读 · 0 评论 -
hdu 4939 Stupid Tower Defense(DP)2014多校训练第7场
Stupid Tower Defense Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Problem Desc原创 2014-08-13 08:54:08 · 2349 阅读 · 0 评论 -
NYOJ 1075 (递推 + 矩阵快速幂)
“红色病毒”问题时间限制:1000 ms | 内存限制:65535 KB难度:4描述医学研究者最近发现了一种新病毒,因为其蔓延速度与曾经在Internet上传播的“红色代码”不相上下,故被称为“红色病毒”。经研究发现,该病毒及其变种的DNA序列中,腺嘌呤(A)、胞嘧啶(C)均是成对出现的。LYH想知道在这种特征下,所有可能成为该病毒的DNA序列的个数。输入多组测试数据。原创 2014-09-29 08:03:13 · 1778 阅读 · 0 评论 -
超大背包问题(01背包)
超大背包问题:有n个重量和价值分别为w[i]和v[i]的物品,从这些物品中挑选总重量不超过W的物品,求所有挑选方案中价值总和的最大值。其中,1 ≤ n ≤ 40, 1 ≤ w[i], v[i] ≤ 10^15, 1 ≤ W ≤ 10^15.这个问题给人的第一感觉就是普通的01背包。不过,看完数据范围会发现,这次价值和重量都可以是非常大的数值,相比之下n比较小。使用DP求解背包为题的复杂度是O(原创 2014-10-08 09:48:43 · 12281 阅读 · 2 评论 -
POJ 1552 BUY LOW, BUY LOWER(最长单调递减子序列求方案数)
BUY LOW, BUY LOWERTime Limit: 1000MS Memory Limit: 30000K DescriptionThe advice to "buy low" is half the formula to success in the bovine stock market.To be con原创 2015-04-30 11:25:54 · 1560 阅读 · 0 评论 -
POJ 1837 Balance(动态规划之背包问题)
BalanceTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 11436 Accepted: 7130DescriptionGigel has a strange "balance" and he wants to poise it. Actually,原创 2015-04-15 20:12:42 · 2295 阅读 · 1 评论 -
Bnuoj 4275 Your Ways(数学题 + 动态规划)
Your Ways You live in a small well-planned rectangular town in Phuket. The size of the central area of the town is H kilometers x W kilometers. The central area is divided into HW unit blocks, e原创 2015-04-19 19:37:52 · 1340 阅读 · 0 评论 -
FZOJ 2014年11月份月赛 ytaaa(dp + RMQ)
题目链接:http://acm.fzu.edu.cn/contest/problem.php?cid=140&sortid=3Problem DescriptionYtaaa作为一名特工执行了无数困难的任务,这一次ytaaa收到命令,需要炸毁敌人的一个工厂,为此ytaaa需要制造一批炸弹以供使用。 Ytaaa使用的这种新型炸弹由若干个炸药组成,每个炸药都有它的威力值,而炸弹的威力值为组原创 2014-11-16 20:57:38 · 1928 阅读 · 2 评论 -
ZOJ 2319 Beatuiful People(单调上升子序列变形)
Beautiful PeopleTime Limit: 5 Seconds Memory Limit: 32768 KB Special JudgeThe most prestigious sports club in one city has exactly N members. Each of its members is strong and beauti原创 2014-10-02 11:30:04 · 1700 阅读 · 0 评论 -
ZOJ 3805 Machine(简单dp)
MachineTime Limit: 2 Seconds Memory Limit: 65536 KBIn a typical assembly line, machines are connected one by one. The first machine's output product will be the second machine's raw mater原创 2014-11-12 16:02:52 · 1573 阅读 · 0 评论 -
hdu 1565 方格取数(1)(状态压缩dp)
方格取数(1) Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Problem Description给你一个n*n的格子的棋原创 2014-10-10 18:03:15 · 2364 阅读 · 0 评论 -
poj 1185 && NYOJ 85 炮兵阵地(状态压缩dp)
炮兵阵地时间限制:2000 ms | 内存限制:65535 KB难度:6描述司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队。一个N*M的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示),也可能是平原(用"P"表示),如下图。在每一格平原地形上最多可以布置一支炮兵部队(山地上不能够部署炮兵部队);一支炮兵部队在地图上的攻击范围如图中黑色区域所原创 2014-10-10 10:29:08 · 5215 阅读 · 2 评论 -
状态压缩dp入门 第一题 POJ 3254 Corn Fields
Corn FieldsTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 6460 Accepted: 3436DescriptionFarmer John has purchased a lush new rectangular pasture compos原创 2014-04-29 09:41:02 · 5140 阅读 · 0 评论 -
BNUOJ 4064 条形码设计 (动态规划 + 递推)
条形码设计Time Limit: 1000ms Memory Limit: 65536KB64-bit integer IO format: %lld Java class name: Main校ACM队准备筹划向学校批请一个专用机房。但是为了防止原创 2014-03-13 09:27:40 · 1553 阅读 · 0 评论 -
hdu 1058 Humble Numbers (DP)
Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Problem Descr原创 2014-02-20 19:58:52 · 3403 阅读 · 0 评论 -
UVA 10465 - Homer Simpson 贪心
Homer SimpsonTime Limit: 3 secondsMemory Limit: 32 MBHomer Simpson, a very smart guy, likes eating Krusty-burgers. It takes Homer m minutes to eat a Krusty- burger. However原创 2013-08-02 18:29:27 · 1817 阅读 · 0 评论 -
hdu 4501 小明系列故事——买年货 多重背包
小明系列故事——买年货 Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Problem Description原创 2013-04-09 20:54:20 · 1530 阅读 · 0 评论 -
hdu 1257最少拦截系统 动态规划
最少拦截系统Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Problem Description某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一原创 2013-01-24 10:55:57 · 4833 阅读 · 0 评论 -
hdu 1081 To The Max 基础dp
To The MaxTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Problem DescriptionGiven a two-dimensional array of positive and negative integers, a sub-rec原创 2013-04-10 09:12:13 · 1434 阅读 · 0 评论 -
NYOJ 201 作业题 动态规划
作业题时间限制:3000 ms | 内存限制:65535 KB难度:3描述小白同学这学期有一门课程叫做《数值计算方法》,这是一门有效使用数字计算机求数学问题近似解的方法与过程,以及由相关理论构成的学科……今天他们的Teacher S,给他们出了一道作业题。Teacher S给了他们很多的点,让他们利用拉格朗日插值公式,计算出某严格单调函数的曲线。原创 2013-03-26 21:14:48 · 1163 阅读 · 0 评论 -
hdu 1881 毕业bg
毕业bg Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Problem Description原创 2013-03-23 21:25:44 · 1472 阅读 · 0 评论 -
hdu 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 (背包问题)
悼念512汶川大地震遇难同胞——珍惜现在,感恩生活Time Limit : 1000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other)Problem Description急!灾区的食物依然短缺!为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市原创 2013-01-26 14:57:30 · 868 阅读 · 0 评论 -
NYOJ 49 开心的小明
点击打开链接 很多题都可以通过转化,转化为我们比较熟悉的模型,比如说这个题,我们就可以转化为0-1背包处理。把n当作背包容积,m当作物品个数,v当作每种物品的体积,p*v当作每种物品的价值,这样,求物品的价格与重要度乘积的总和最大值,就相当于求背包的最大价值,就可以用0-1背包的方法来解决问题。所以,遇到问题一定要多想。AC代码:#include#includ原创 2013-01-27 09:53:48 · 2612 阅读 · 0 评论 -
NYOJ 36 最长公共子序列 dp
最长公共子序列点击打开链接时间限制:3000 ms | 内存限制:65535 KB难度:3描述咱们就不拐弯抹角了,如题,需要你做的就是写一个程序,得出最长公共子序列。tip:最长公共子序列也称作最长公共子串(不要求连续),英文缩写为LCS(Longest Common Subsequence)。其定义是,一个序列 S ,如果分别是两个或多个已知序列的子序列,原创 2013-01-26 17:21:04 · 1143 阅读 · 0 评论 -
NYOJ 359 Delete it 字符串处理
Delete it时间限制:2000 ms | 内存限制:65535 KB难度:2描述克林在打一行字母时总是会打多一个字符,比如想打”july”时会打成”juuly”,这样他需要删掉其中一个’u’。克林想知道他可以删掉哪个位置的字符就可以变成他真正想打的一行字母。输入第一行一个整数:T (测试个数)每个测试输入两行,两个字原创 2013-05-02 10:36:10 · 1742 阅读 · 0 评论 -
NYOJ 252 01串 dp
01串时间限制:1000 ms | 内存限制:65535 KB难度:2描述ACM的zyc在研究01串,他知道某一01串的长度,但他想知道不含有“11”子串的这种长度的01串共有多少个,他希望你能帮帮他。注:01串的长度为2时,有3种:00,01,10。输入第一行有一个整数n(0随后有n行,每行有一个整数m(2输出输出不含有“1原创 2013-05-06 09:01:29 · 1636 阅读 · 0 评论 -
UVA 102 - Ecological Bin Packing(动态规划)
Ecological Bin Packing BackgroundBin packing, or the placement of objects of certain weights into different bins subject to certain constraints, is an historically interesting problem.原创 2013-07-30 15:35:57 · 3195 阅读 · 0 评论 -
poj 3211 Washing Clothes 分组01背包
Washing ClothesTime Limit: 1000MS Memory Limit: 131072KDescriptionDearboy was so busy recently that now he has piles of clothes to wash. Luckily, he has a beautiful and h原创 2013-11-30 16:58:50 · 2623 阅读 · 0 评论 -
POJ 3628 Bookshelf 2 (01背包)
Bookshelf 2Time Limit: 1000MS Memory Limit: 65536KDescriptionFarmer John recently bought another bookshelf for the cow library, but the shelf is getting filled up quite原创 2013-11-30 17:22:25 · 2129 阅读 · 2 评论 -
NYOJ练习题 Splits the string (简单动态规划)
Splits the string时间限制:1000 ms | 内存限制:65535 KB描述Hrdv is interested in a string,especially the palindrome string.So he wants some palindrome string.A sequence of characters is a原创 2013-10-20 17:29:25 · 2118 阅读 · 3 评论 -
hdu 1059 Dividing 多重背包
Dividing Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Problem Description原创 2013-04-07 10:54:16 · 1299 阅读 · 0 评论