
动态规划
文章平均质量分 73
轨轨123
菜鸡一个
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
简单dp-LCS最长公共序列
LCS最长公共序列是很普遍的动态规划问题,描述如下:给定二个字符串s1,s2,求出最长的公共子序列,需要注意的是这里的公共子序列不要求是连续的例如:s1="abcad",s2="daba",这里的"aba"就是公共子序列,所以长度为3,还有有可能会有很多个长度为3的子序列。解题思路:这里需要用到二维整型数组dp[i][j]表示的是从s1中前i个字符串和s2中前j个字符串的LCS,我们可以这样递推:...原创 2018-02-27 20:55:29 · 244 阅读 · 0 评论 -
动态规划-vacations
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was c...原创 2018-03-14 16:21:59 · 225 阅读 · 0 评论 -
动态规划-一卡通大冒险
因为长期钻研微积分, 麻神至今单身,某天,麻神想到了一个方法,把自己的联系方式写在学生卡的背面,然后故意将自己的卡"遗失"在某处(如水房,LS,NB ,SB ,食堂。。。。)他们希望能有MM看到他们遗失卡,能主动跟他们联系,这样就有机会请MM吃饭了。他将自己的学生卡夹在基本相同的书里,然后再将书遗失到校园的各个角落。当他为自己的至少啧啧赞叹时,发一个问题,很明显,如果只有一张校园卡,那么只有一种方...原创 2018-03-14 16:10:35 · 200 阅读 · 0 评论 -
charm-bracelet
Bessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from the N (1 ≤ N ≤ 3,402) available charms. Each charm i in the ...原创 2018-03-13 16:09:31 · 269 阅读 · 0 评论 -
简单dp-max sum
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 + (-1) + 5 + 4 = 14. InputThe fir...原创 2018-03-13 16:00:40 · 373 阅读 · 0 评论 -
简单dp-命运
穿过幽谷意味着离大魔王lemon已经无限接近了! 可谁能想到,yifenfei在斩杀了一些虾兵蟹将后,却再次面临命运大迷宫的考验,这是魔王lemon设下的又一个机关。要知道,不论何人,若在迷宫中被困1小时以上,则必死无疑! 可怜的yifenfei为了去救MM,义无返顾地跳进了迷宫。让我们一起帮帮执着的他吧! 命运大迷宫可以看成是一个两维的方格阵列,如下图所示: yifenfei一开始在左上角,目...原创 2018-03-13 15:38:33 · 310 阅读 · 0 评论 -
简单dp-bone collector
题目:Many 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 he went to the grave …The bone collecto...原创 2018-03-12 20:04:26 · 300 阅读 · 1 评论 -
动态规划:poj-1837 Balance
Gigel has a strange "balance" and he wants to poise it. Actually, the device is different from any other ordinary balance. It orders two arms of negligible weight and each arm's length is 15. Some hoo...原创 2018-03-22 13:29:00 · 200 阅读 · 0 评论 -
简单dp-数字三角问题
这个问题也是简单dp问题题意:给定一个由n行数字组成的数字三角形,如下图所示: 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 试设计一个算法,计算出从三角形的顶至底的一条路径,使该路径经过的数字总和最大(每一步只能从一个数走到下一层上和它最近的左边的数或者右边的...原创 2018-02-23 16:57:24 · 194 阅读 · 0 评论 -
简单dp-poj-1260
题目链接:http://poj.org/problem?id=1260题目大意:珠宝分成很多类,每一类需要花费的价格是不一样的,给出需要的珠宝的数量和价格,然后最后求出最省钱的方式。比如说:现在有两种珠宝需要买他们需要的数量和单价分别是100 ,1和100, 2,题目的意思是当购买时需要多买10个,而且可以用单价比较高的买单价低的也是可以的,所以这时候就有最优方案,这里方案一是:(100+10)*...原创 2018-02-23 16:31:59 · 275 阅读 · 0 评论 -
动态规划-how to type
Pirates have finished developing the typing software. He called Cathy to test his typing software. She is good at thinking. After testing for several days, she finds that if she types a string by some...原创 2018-03-15 09:44:09 · 374 阅读 · 2 评论 -
简单dp-删除最少字符变成回文串
题目描述:给定一字符串s,求最少删除多少个字符可以使得s成为回文串。例如:s="abca",答案是1.解题思路:这里提供两种解题方法,第一种是用到上一篇写的LCS(最长公共子串),第二种是直接的dp。1,第一种思路就是申请s2变量,使得s2是s1的反转,如果是回文串的话,那么就等价于求s2和s1的LCS,例如s1=abca,s2=acba,公共子串的长度为3(aba ,aca),所以需要删除的字符...原创 2018-02-27 21:19:43 · 1850 阅读 · 0 评论 -
第十四届华中科技大学程序设计竞赛决赛同步赛 F-beautiful Land
链接:https://www.nowcoder.com/acm/contest/119/F来源:牛客网时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 131072K,其他语言262144K 64bit IO Format: %lld题目描述It’s universally acknowledged that there’re innumerable trees in the camp...原创 2018-05-07 19:03:02 · 199 阅读 · 0 评论