算法之动态规划
cc_wood
这个作者很懒,什么都没留下…
展开
-
HDU 1003 Max Sum
Max SumGiven a sequence a11,a22,a33......ann, 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 + (-1) + 5 + 4 = 14. InputThe原创 2017-04-19 13:08:27 · 293 阅读 · 0 评论 -
Beans HDU - 2845 (dp)
题目链接:点我 Bean-eating is an interesting game, everyone owns an M*N matrix, which is filled with different qualities beans. Meantime, there is only one bean in any 1*1 grid. Now you want to eat the beans原创 2017-08-07 14:01:31 · 235 阅读 · 0 评论 -
Fruit HDU - 2152 (dp计数问题)
题目链接:点我 转眼到了收获的季节,由于有TT的专业指导,Lele获得了大丰收。特别是水果,Lele一共种了N种水果,有苹果,梨子,香蕉,西瓜……不但味道好吃,样子更是好看。于是,很多人们慕名而来,找Lele买水果。甚至连大名鼎鼎的HDU ACM总教头 lcy 也来了。lcy抛出一打百元大钞,"我要买由M个水果组成的水果拼盘,不过我有个小小的要求,对于每种水果,个数上我有限制,既不能少于某个特定值,原创 2017-08-05 10:15:12 · 366 阅读 · 0 评论 -
Investment HDU - 1963(完全背包)
题目链接:点我John never knew he had a grand-uncle, until he received the notary’s letter. He learned that his late grand-uncle had gathered a lot of money, somewhere in South-America, and that John was the o原创 2017-08-05 10:09:10 · 194 阅读 · 0 评论 -
FatMouse and Cheese HDU - 1078
题目链接:点我 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 < n. At each grid locatio原创 2017-08-11 22:56:56 · 178 阅读 · 0 评论 -
Partitioning by Palindromes UVA - 11584
题目链接:点我题意:给你一个字符串,问最少能分成几个回文串.思路:动态规划,dp[i]表示 1 到 i 最少可以分成几个回文串,则dp[i] = min(dp[i], dp[j] + 1) && judge(j,i) : 表示由 j + 1 到 i 能形成回文串.代码:#include<cstring>#include<cstdio>#include<algorithm>#include<cm原创 2017-08-11 22:50:18 · 168 阅读 · 0 评论 -
The Tower of Babylon UVA - 437
题目链接:点我 Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this talehave been forgotten. So now, in line with the educational nature of this contest, we will tell原创 2017-08-11 22:40:14 · 245 阅读 · 0 评论 -
HDU 2048 数塔
在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少? 已经告诉你了,这是个DP的题目,你能AC吗?Input输入数据首先包括一个整数C,表示测试实例的个数,每个测试实例的第一行是一个整数N(1 <= N <= 100),表示数塔的高度,接下来用N行数字表示数塔,其中第i行有个i个整数原创 2017-04-11 13:05:07 · 266 阅读 · 0 评论 -
HDU2546 饭卡
饭卡 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够)。所以大家都希望尽量使卡上的余额最少。 某天,食堂中有n种菜出售,每种菜可购买一次。已知每种菜的价格以及卡上的余额,问最少可使卡上的余额为多少。 Input多组数据。对于每组数据: 第一行为正整数n,原创 2017-04-11 13:19:10 · 266 阅读 · 0 评论 -
POJ 1088 滑雪
滑雪Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子 1 2 3 4 516 17 18 19 615 24 25 20 714 23 22 21 813 12 11 10 9原创 2017-04-13 12:37:45 · 190 阅读 · 0 评论 -
HDU 2191 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活
悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 急!灾区的食物依然短缺! 为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都是袋装产品,其价格不等,并且只能整袋购买。 请问:你用有限的资金最多能采购多少公斤粮食呢? 后记: 人生是一个充满了变数的生命过程,天灾、人祸、病痛是我们生命历程中不可预知的威胁。 月有阴晴圆原创 2017-04-14 13:12:18 · 426 阅读 · 0 评论 -
POJ 2533 Longest Ordered Subsequence
Longest Ordered Subsequence A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence ( a1, a2, ..., aN) be any sequence ( ai1, ai2, ..., aiK), where原创 2017-04-14 13:50:37 · 186 阅读 · 0 评论 -
POJ 2955 - Brackets
BracketsWe give the following inductive definition of a “regular brackets” sequence:the empty sequence is a regular brackets sequence,if s is a regular brackets sequence, then (s) and [s] are regular原创 2017-04-17 13:10:12 · 201 阅读 · 0 评论 -
HDU 1176- 免费馅饼
* 免费馅饼 *都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼。说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内。馅饼如果掉在了地上当然就不能吃了,所以gameboy马上卸下身上的背包去接。但由于小径两侧都不能站人,所以他只能在小径上接。由于gameboy平时老呆在房间里玩游戏,虽然在游戏中是个身手敏捷的高手,但在现实中运原创 2017-04-17 13:18:29 · 220 阅读 · 0 评论 -
Snakes and Ladders LightOJ - 1151 概率dp + 高斯消元
题目链接'Snakes and Ladders' or 'Shap-Ludu' is a game commonly played in Bangladesh. The game is so common that it would be tough to find a person who hasn't played it. But those who haven't played it (unl原创 2017-09-07 19:14:50 · 764 阅读 · 0 评论