![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
动态规划
文章平均质量分 78
小鸡炖蘑菇_
stay hungry,stay foolish.
展开
-
HDU 2602 Bone Collector
HDU 2602 Bone CollectorProblem DescriptionMany years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also h原创 2015-08-16 16:21:40 · 333 阅读 · 0 评论 -
hdu3466-Proud Merchants
linkProblem DescriptionRecently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very原创 2015-12-02 16:31:16 · 523 阅读 · 0 评论 -
树形dp问题(持续更新中...)
hdu 1561 代码:#include <iostream>#include <cstdio>#include <cstring>#include <vector>using namespace std;const int M = 220;int n, m, v[M];vector<int>son[M];int dp[M][M];void dfs(int num, int le原创 2015-12-02 16:25:28 · 338 阅读 · 0 评论 -
hdu-1069-Monkey and Banana(动态规划)
Problem DescriptionA group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some b原创 2016-01-04 17:11:47 · 699 阅读 · 0 评论 -
HDU-1114-Piggy-Bank(完全背包)
Problem DescriptionBefore ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action comes from Irreversibly Bound Money (IBM). The ide原创 2016-01-05 10:23:12 · 281 阅读 · 0 评论 -
HDU-2191-悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(多重背包)
Problem Description急!灾区的食物依然短缺! 为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都是袋装产品,其价格不等,并且只能整袋购买。 请问:你用有限的资金最多能采购多少公斤粮食呢?后记: 人生是一个充满了变数的生命过程,天灾、人祸、病痛是我们生命历程中不可预知的威胁。 月有阴晴圆缺,人有旦夕祸福原创 2016-01-05 10:18:32 · 275 阅读 · 0 评论 -
HDU-2844-Coins
Problem DescriptionWhuacmers use coins.They have coins of value A1,A2,A3…An Silverland dollar. One day Hibix opened purse and found there were some coins. He decided to buy a very nice watch in a nearb原创 2016-01-05 12:22:06 · 350 阅读 · 0 评论 -
HDU-1712-ACboy needs your help(分组背包)
Problem DescriptionACboy has N courses this term, and he plans to spend at most M days on study.Of course,the profit he will gain from different course depending on the days he spend on it.How to arran原创 2016-01-05 15:08:33 · 414 阅读 · 0 评论 -
HDU-3496-Watch The Movie(二维01背包问题)
Problem DescriptionNew semester is coming, and DuoDuo has to go to school tomorrow. She decides to have fun tonight and will be very busy after tonight. She like watch cartoon very much. So she wants h原创 2016-01-05 19:29:00 · 821 阅读 · 0 评论 -
HDU-3466-Proud Merchants(01背包问题)
Problem DescriptionRecently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very pro原创 2016-01-05 21:49:45 · 391 阅读 · 0 评论 -
动态规划求最长递增子序列
最长递增子序列问题是一个很基本、较常见的小问题,但这个问题的求解方法却并不那么显而易见,需要较深入的思考和较好的算法素养才能得出良好的算法。由于这个问题能运用学过的基本的算法分析和设计的方法与思想,能够锻炼设计较复杂算法的思维,我对这个问题进行了较深入的分析思考,得出了几种复杂度不同算法,并给出了分析和证明。一, 最长递增子序列问题的描述设L=<a1,a2,…,an>是n个不同的实数的序列,L原创 2015-08-18 18:37:24 · 6168 阅读 · 1 评论 -
求所有最大公共子序列的算法实现(转)
最近看了很多关于LCS(Longest common subsequence problem,最长公共子序列)的文章,大部分问题都只是求出最大公共子序列的长度,或者打印处其中的任意一个最大子序列即可,但是如何快速的打印出所有的最大长度子序列?这个问题好像看到的不多。本文给出了传统的DP(dynamic programming,动态规划)算法进行求解的过程,并用c语言实现。另外参考一篇论文实现了其中的转载 2015-08-17 21:10:20 · 1901 阅读 · 0 评论 -
动态规划算法
一、基本概念动态规划过程是:每次决策依赖于当前状态,又随即引起状态的转移。一个决策序列就是在变化的状态中产生出来的,所以,这种多阶段最优化决策解决问题的过程就称为动态规划。二、基本思想与策略基本思想与分治法类似,也是将待求解的问题分解为若干个子问题(阶段),按顺序求解子阶段,前一子问题的解,为后一子问题的求解提供了有用的信息。在求解任一子问题时,列出各种可能的局部解,通过决策保留那些有可能达到最优转载 2015-08-17 19:39:46 · 416 阅读 · 0 评论 -
最长上升子序列 LIS(Longest Increasing Subsequence)(转)
引出:问题描述:给出一个序列a1,a2,a3,a4,a5,a6,a7….an,求它的一个子序列(设为s1,s2,…sn),使得这个子序列满足这样的性质,s1<s2<s3<…<sn并且这个子序列的长度最长。输出这个最长的长度。(为了简化该类问题,我们将诸如最长下降子序列及最长不上升子序列等问题都看成同一个问题,其实仔细思考就会发现,这其实只是<符号定义上的问题,并不影响问题的实质) 例如有一个序列:转载 2015-08-16 21:02:15 · 345 阅读 · 0 评论 -
背包之01背包、完全背包、多重背包详解(转)
首先说下动态规划,动态规划这东西就和递归一样,只能找局部关系,若想全部列出来,是很难的,比如汉诺塔。你可以说先把除最后一层的其他所有层都移动到2,再把最后一层移动到3,最后再把其余的从2移动到3,这是一个直观的关系,但是想列举出来是很难的,也许当层数n=3时还可以模拟下,再大一些就不可能了,所以,诸如递归,动态规划之类的,不能细想,只能找局部关系。 (引至杭电课件:DP最关键的就是状态,在DP转载 2015-08-16 16:12:59 · 1225 阅读 · 1 评论 -
HNACM(七)A.物资调度
Description某地区发生了地震,灾区已经非常困难,灾民急需一些帐篷、衣物、食品和血浆等物资。可通往灾区的道路到处都是塌方,70%以上的路面损坏,桥梁全部被毁。国家立即启动应急预案,展开史上最大强度非作战空运行动,准备向灾区空投急需物资。 一方有难,八方支援。现在已知有N个地方分别有A1,A2,….,An个物资可供调配。目前灾区需要物资数量为M。 现在,请你帮忙算一算,总共有多少种物质调度原创 2016-04-04 16:16:55 · 1006 阅读 · 0 评论 -
POJ 1458/HDU 1159 最长公共子序列 (动态规划)
题目链接:poj && hdu求最长公共子序列的方法:http://blog.csdn.net/qq_21120027/article/details/47732257代码#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int M = 10原创 2015-11-28 11:52:45 · 396 阅读 · 0 评论 -
HDU 1297 Children’s Queue
Problem DescriptionThere are many students in PHT School. One day, the headmaster whose name is PigHeader wanted all students stand in a line. He prescribed that girl can not be in single. In other wor原创 2015-11-22 22:28:16 · 293 阅读 · 0 评论 -
HDU 1203 I NEED A OFFER!
HDU 1203 I NEED A OFFER!Problem Description Speakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了。要申请国外的任何大学,你都要交纳一定的申请费用,这可是很惊人的。Speakless没有多少钱,总共只攒了n万美元。他将在m个学校中选择若干的(当然要在他的经济承受范围内)。每个学校都有不同的申请费用原创 2015-08-19 19:46:15 · 360 阅读 · 0 评论 -
hdu 2084 数塔
hdu 2084 数塔Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的:有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少? 已经告诉你了,这是个DP的题目,你能AC吗?Input 输入数据首先包括一个整数C,表示测试实例的个数,每个测试实例的第一行是一个整数N(1 <= N <= 10原创 2015-08-17 18:53:27 · 317 阅读 · 0 评论 -
HDU 1257 最少拦截系统
HDU 1257 最少拦截系统Problem Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹. 怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个原创 2015-08-17 18:59:11 · 320 阅读 · 0 评论 -
POJ 1088 滑雪
POJ 1088 滑雪Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子 1 2 3 4 516 17 18 19 615 24 25 20 714 2原创 2015-08-17 19:06:43 · 450 阅读 · 0 评论 -
hdu 1003 Max Sum
hdu 1003 Max SumProblem Description Given a sequence a[1],a[2],a[3]……a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 +原创 2015-08-17 18:43:29 · 72 阅读 · 0 评论 -
LightOJ 1110 An Easy LCS
LightOJ 1110 An Easy LCS LCS means ‘Longest Common Subsequence’ that means two non-empty strings are given; you have to find the Longest Common Subsequence between them. Since there can be many solutio原创 2015-08-17 20:58:20 · 625 阅读 · 0 评论 -
hdu 1087 Super Jumping! Jumping! Jumping!
hdu 1087 Super Jumping! Jumping! Jumping!Problem Description Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little原创 2015-08-17 19:32:51 · 334 阅读 · 0 评论 -
ZOJ 1107 FatMouse and Cheese
ZOJ 1107 FatMouse and Cheese FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension n: each grid location is labelled (p,q) where 0 <= p < n and 0 <= q <原创 2015-08-18 17:58:26 · 411 阅读 · 0 评论 -
hdu 5366 The mook jong
hdu 5366 The mook jongProblem Description ZJiaQ want to become a strong man, so he decided to play the mook jong。ZJiaQ want to put some mook jongs in his backyard. His backyard consist of n bricks tha原创 2015-08-18 18:52:57 · 415 阅读 · 0 评论 -
HUD 1058 Humble Numbers
HUD 1058 Humble NumbersProblem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25,原创 2015-08-18 18:07:48 · 295 阅读 · 0 评论 -
HDU 1160 FatMouse's Speed
HDU 1160 FatMouse’s SpeedProblem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a su原创 2015-08-18 18:45:59 · 370 阅读 · 0 评论 -
hdu1421搬寝室
hdu1421搬寝室Problem Description 搬寝室是很累的,xhd深有体会.时间追述2006年7月9号,那天xhd迫于无奈要从27号楼搬到3号楼,因为10号要封楼了.看着寝室里的n件物品,xhd开始发呆,因为n是一个小于2000的整数,实在是太多了,于是xhd决定随便搬2*k件过去就行了.但还是会很累,因为2*k也不小是一个不大于n的整数.幸运的是xhd根据多年的搬东西的经验发现每原创 2015-08-18 19:38:33 · 420 阅读 · 0 评论 -
HDU 1025 Constructing Roads In JGShining's Kingdom
HDU 1025 Constructing Roads In JGShining’s KingdomProblem Description JGShining’s kingdom consists of 2n(n is no more than 500,000) small cities which are located in two parallel lines.Half of these c原创 2015-08-19 19:24:24 · 330 阅读 · 0 评论 -
UVA 562 - Dividing coins
UVA 562 - Dividing coinsIt’s commonly known that the Dutch have invented copper-wire. Two Dutch men were fighting over a nickel, which was made of copper. They were both so eager to get it and the figh原创 2015-08-19 19:41:00 · 424 阅读 · 0 评论 -
UVA 674 - Coin Change
UVA 674 - Coin Change Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money.For example, if we have 1原创 2015-08-19 19:11:26 · 429 阅读 · 0 评论 -
HDU 1506 Largest Rectangle in a Histogram
HDU 1506 Largest Rectangle in a HistogramProblem Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have原创 2015-08-19 19:29:37 · 322 阅读 · 0 评论 -
zzuoj-10451: 数字卡片游戏
传送门动态规划问题 f[i][j]表示剩下区间[i,j]后,取完该区间所有卡片的最优解差值。规定值为正数表示,A胜; 若下一张卡片为A取,则dp[i][j] = max(dp[i+1][j]+num[i], dp[i][j-1]+num[j]);; 若下一张卡片为B取,则dp[i][j] = min(dp[i+1][j]-num[i], dp[i][j-1]-num[j]);;#include原创 2016-03-27 15:24:21 · 1054 阅读 · 0 评论