
动态规划——区间 DP
文章平均质量分 63
区间 DP
Alex_McAvoy
想要成为渔夫的猎手
展开
-
动态规划 —— 区间 DP
【概述】区间型动态规划,又称为合并类动态规划,是线性动态规划的扩展,它在分阶段地划分问题时,与阶段中元素出现的顺序和由前一阶段的区间中哪些元素合并而来有很大的关系。实质上就是在一个区间上进行的动态规划,不仅要满足 DP 问题的最优子结构,还要符合在区间上操作的特点。其主要思想就是在小区间进行 DP 得到最优解,然后再利用小区间的最优解合并求大区间的最优解。往往会枚举区间,将区间分成...原创 2018-08-17 10:14:33 · 1564 阅读 · 2 评论 -
动态规划 —— 区间 DP —— 石子合并三讲
石子合并问题是最经典的 DP 问题,其有如下3种题型:【任意合并】1.问题:有N堆石子,现要将石子有序的合并成一堆,规定如下:每次只能移动任意的2堆石子合并,合并花费为新合成的一堆石子的数量。求将这N堆石子合并成一堆的总花费最小(或最大)。2.分析:最简单的情况,合并的是任意两堆,直接贪心即可,每次选择最小的两堆合并,实际上就是哈夫曼树的变形。3.实现:int Com...转载 2018-08-17 10:48:04 · 974 阅读 · 3 评论 -
能量项链(NOIP-2006 提高组)
Problem Description在Mars星球上,每个Mars人都随身佩带着一串能量项链。在项链上有N颗能量珠。能量珠是一颗有头标记与尾标记的珠子,这些标记对应着某个正整数。并且,对于相邻的两颗珠子,前一颗珠子的尾标记一定等于后一颗珠子的头标记。因为只有这样,通过吸盘(吸盘是Mars人吸收能量的一种器官)的作用,这两颗珠子才能聚合成一颗珠子,同时释放出可以被吸盘吸收的能量。如果前一颗能...原创 2018-09-03 00:01:36 · 2010 阅读 · 1 评论 -
Running(POJ-3661)
Problem DescriptionThe cows are trying to become better athletes, so Bessie is running on a track for exactly N (1 ≤ N ≤ 10,000) minutes. During each minute, she can choose to either run or rest for...原创 2018-05-29 20:12:09 · 535 阅读 · 0 评论 -
石子合并问题--直线版(Hrbust-1818)
Problem Description一条直线上摆放着一行共n堆的石子。现要将石子有序地合并成一堆。规定每次只能选相邻的两堆合并成新的一堆,并将新的一堆石子数记为该次合并的得分。请编辑计算出将n堆石子合并成一堆的最小得分和将n堆石子合并成一堆的最大得分。Input输入有多组测试数据。每组第一行为n(n<=100),表示有n堆石子,。二行为n个用空格隔开的整数,依次表...原创 2018-09-01 11:39:25 · 1404 阅读 · 0 评论 -
String painter(HDU-2476)
Problem DescriptionThere are two strings A and B with equal length. Both strings are made up of lower case letters. Now you have a powerful string painter. With the help of the painter, you can chan...原创 2018-09-01 11:27:35 · 708 阅读 · 0 评论 -
Halloween Costumes(LightOJ-1422)
Problem DescriptionGappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is planning to attend as many parties as he can. Since it's Halloween, these parties are al...原创 2018-08-28 19:19:49 · 298 阅读 · 0 评论 -
Multiplication Puzzle(POJ-1651)
Problem DescriptionThe multiplication puzzle is played with a row of cards, each containing a single positive integer. During the move player takes one card out of the row and scores the number of p...原创 2018-08-17 16:31:57 · 475 阅读 · 0 评论 -
You Are the One(HDU-4283)
Problem DescriptionThe TV shows such as You Are the One has been very popular. In order to meet the need of boys who are still single, TJUT hold the show itself. The show is hold in the Small hall, ...原创 2018-08-17 16:06:41 · 847 阅读 · 0 评论 -
Two Rabbits(HDU-4757)
Problem DescriptionLong long ago, there lived two rabbits Tom and Jerry in the forest. On a sunny afternoon, they planned to play a game with some stones. There were n stones on the ground and they...原创 2018-08-17 13:46:10 · 420 阅读 · 0 评论 -
Palindrome subsequence(HDU-4632)
Problem DescriptionIn mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, ...原创 2018-08-17 12:47:46 · 351 阅读 · 0 评论 -
释放囚犯(洛谷-P1622)
题目描述Caima王国中有一个奇怪的监狱,这个监狱一共有P个牢房,这些牢房一字排开,第i个紧挨着第i+1个(最后一个除外)。现在正好牢房是满的。上级下发了一个释放名单,要求每天释放名单上的一个人。这可把看守们吓得不轻,因为看守们知道,现在牢房中的P个人,可以相互之间传话。如果某个人离开了,那么原来和这个人能说上话的人,都会很气愤,导致他们那天会一直大吼大叫,搞得看守很头疼。如果给这些要发火...原创 2018-08-17 12:06:23 · 1005 阅读 · 0 评论 -
石子合并(洛谷-P1880)
题目描述在一个圆形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分。试设计出1个算法,计算出将N堆石子合并成1堆的最小得分和最大得分.输入输出格式输入格式:数据的第1行试正整数N,1≤N≤100,表示有N堆石子.第2行有N个数,分别表示每堆石子的个数.输出格式:输出共2行,第1行为最小...原创 2018-08-17 10:22:19 · 1078 阅读 · 0 评论 -
传球游戏(洛谷-P1057)
题目描述上体育课的时候,小蛮的老师经常带着同学们一起做游戏。这次,老师带着同学们一起做传球游戏。游戏规则是这样的:n 个同学站成一个圆圈,其中的一个同学手里拿着一个球,当老师吹哨子时开始传球,每个同学可以把球传给自己左右的两个同学中的一个(左右任意),当老师再次吹哨子时,传球停止,此时,拿着球没有传出去的那个同学就是败者,要给大家表演一个节目。聪明的小蛮提出一个有趣的问题:有多少种不...原创 2018-08-19 22:20:42 · 2150 阅读 · 0 评论 -
Brackets(POJ-2955)
Problem DescriptionWe 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...原创 2018-08-18 10:00:16 · 446 阅读 · 0 评论 -
Brackets Sequence(POJ-1141)
Problem DescriptionLet us define a regular brackets sequence in the following way:1. Empty sequence is a regular sequence.2. If S is a regular sequence, then (S) and [S] are both regular sequen...原创 2018-08-18 09:44:39 · 843 阅读 · 0 评论 -
合并石子(信息学奥赛一本通-T1274)
【题目描述】在一个操场上一排地摆放着N堆石子。现要将石子有次序地合并成一堆。规定每次只能选相邻的2堆石子合并成新的一堆,并将新的一堆石子数记为该次合并的得分。计算出将N堆石子合并成一堆的最小得分。【输入】第一行为一个正整数N (2≤N≤100);以下N行,每行一个正整数,小于10000,分别表示第i堆石子的个数(1≤i≤N)。【输出】一个正整数,即最小得分。【输入样...原创 2018-06-04 21:58:10 · 3169 阅读 · 1 评论 -
Cheapest Palindrome(POJ-3280)
Problem DescriptionKeeping track of all the cows can be a tricky task so Farmer John has installed a system to automate it. He has installed on each cow an electronic ID tag that the system will rea...原创 2018-06-07 14:46:41 · 276 阅读 · 0 评论