![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
~~~~~~~~~~动态规划
文章平均质量分 78
zzuspy
本人初学者~~
展开
-
大白书DP习题
9月7号~开学啦,时间有点紧张。。暑假算是白费啦~今天开始刷大白书DP习题。。一天一个!废话不多说。。开刷!Partitioning by Palindromes第一天~题目传送:UVA - 11584 - Partitioning by Palindromes分类:DP入门题。分析:因为是考虑回文串,很容易想到用两个指针来找以当前点为中点的回文串,每次找到一个回文串就进行更新,不过要注意偶数回文和原创 2015-09-18 23:22:53 · 885 阅读 · 0 评论 -
UVA - 10635 - Prince and Princess (LCS转化为LIS)
题目传送:UVA - 10635思路:直接思路是两个串的LCS,不过这个题可以转化为LIS,因为说了序列中各个元素互不相同,所以可以来个映射算出第二个字符串中的字符对应第一个字符串中字符的位置(不存在即删去),然后算出这些位置的LIS即可AC代码:#include #include #include #include #include #include #i原创 2015-05-04 14:36:06 · 716 阅读 · 0 评论 -
POJ - 1080 - Human Gene Functions (LCS的变形)
题目传送:Human Gene Functions思路:LCS的变形,定义状态dp[ i ][ j ]为取字符串s前i个字符字符串t前j个字符所获得的最大值,则可以得到状态转移方程为:dp[ i ][ j ] = max(dp[ i ][ j - 1] + f[ ' - ' ][ t[ j ] ], dp[ i - 1 ][ j ] + f[ s [ i ] ][ ' - ' ],原创 2015-05-04 23:21:59 · 694 阅读 · 0 评论 -
POJ - 2192 - Zipper (简单DP)
题目传送:Zipper思路:设状态DP[i][j]为字符串A前i个字符和B前j个字符能否组成C的前i+j个字符,能则为true,否则falseAC代码:#include #include #include #include #include #include #include #include #include #include #include原创 2015-05-04 00:07:37 · 681 阅读 · 0 评论 -
UVA - 116 - Unidirectional TSP (简单DP + 打印路径)
题目传送: UVA - 116思路:可以定义状态为dp[i][j] 为从第i行第j列开始往后走到第n列(总共n列)的最小值(赋初始值为无穷),且状态方程很好推出来:dp[i][j] = a[i][j] + max(dp[i-1][j+1], dp[i][j+1], dp[i+1][j+1]); 最后最优解 ans = max(dp[i][1])(1不过这题难点不在这原创 2015-04-20 20:53:16 · 682 阅读 · 0 评论 -
UVA - 10192 - Vacation (LCS)
题目传送:UVA - 10192思路:就是简单的最长公共子序列啦,不过输入居然还包含空格,然后很奇怪的TLE了,不是WA,心想n最大才100居然TLE,,好吧,可能有些数据特殊吧AC代码:#include #include #include using namespace std;char s1[105], s2[105];int dp[10原创 2015-04-20 23:41:04 · 700 阅读 · 0 评论 -
HDU-2602-Bone Collector (最基础DP!!)
Bone CollectorTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 31922 Accepted Submission(s): 13138Problem DescriptionMany year原创 2014-11-22 15:19:53 · 1196 阅读 · 0 评论 -
UVA - 147 - Dollars (动态规划)
UVA - 147DollarsTime Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %lluSubmit StatusDescriptionNew Zealand currency consists of $100, $50,原创 2015-03-15 17:04:07 · 866 阅读 · 0 评论 -
UVA - 10405 - Longest Common Subsequence (DP - 最长公共子串)
UVA - 10405Longest Common SubsequenceTime Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %lluSubmit StatusDescriptionProblem C: Longest Commo原创 2015-03-15 20:10:04 · 798 阅读 · 0 评论 -
POJ - 1159 - Palindrome (LCS + 优化)
题目传送:Palindrome思路:一看题目思路很清晰,就是求出字符串s和倒转s后的字符串t的最长公共子序列,但是一看空间开销有点大,如果开int就会爆,5000*5000有100MB了,这里可以开short int,差不多正好可以过去,还有一种做法就是弄一个滚动数组,因为求LCS,根据状态转移方程可以知道,只需要前一行和当前行就行了,所以开个2*5005就OK了,具体看代码原创 2015-05-04 21:13:44 · 625 阅读 · 0 评论 -
UVA - 10891 - Game of Sum (DP)
题目传送:UVA - 10891思路:定义dp(i,j)表示原序列中的第i~j个元素组成的子序列,在双方都采取最优策略的情况下,先手得分的最大值通过枚举给对方剩下怎样的子序列,有状态转移方程为:dp(i, j) = sum(i, j) - min{d(i+1, j), d(j, j) ,d(i,j-1),...,d(i,i),0};AC代码①(On^原创 2015-05-04 17:43:34 · 494 阅读 · 0 评论 -
POJ - 1458 - Common Subsequence (LCS)
题目传送:Common Subsequence思路:LCSAC代码:#include #include #include #include #include #include #include #include #include #include #include #include #define LL long long#define INF原创 2015-05-04 21:52:48 · 588 阅读 · 0 评论 -
树形DP问题
Placing Lampposts题目传送:UVA - 10859 - Placing Lampposts巧妙的思想: 对于有两个需要优化的量v1和v2的时候,要求首先满足v1最小,在v1相同的情况下v2最小,则这里可以把二者组合成一个量M*v1+v2,其中M是一个比”v2的最大理论值和v2的最小理论值之差”还要大的数。AC代码:#include <map>#include <set>#i原创 2015-09-03 10:11:38 · 543 阅读 · 0 评论 -
状压DP问题
状态压缩·一题目传送:#1044 : 状态压缩·一AC代码:#include <map>#include <set>#include <list>#include <cmath>#include <deque>#include <queue>#include <stack>#include <bitset>#include <cctype>#include <cstdio>#in原创 2015-08-17 15:00:53 · 1464 阅读 · 0 评论 -
轮廓线动态规划问题
好久木有更新了,感觉都有点陌生了,上个月因为各种奇怪的事情都没有好好刷过题,做过的题也没好好总结,so,这个月再好好努力!Tiling Dominoes题目传送:UVA - 11270 - Tiling Dominoes基础的轮廓线动态规划。AC代码:#include <map>#include <set>#include <list>#include <cmath>#include <de原创 2015-10-02 15:41:01 · 1829 阅读 · 0 评论 -
TSP问题
Hie with the Pie题目传送:POJ - 3311 - Hie with the PieAC代码:#include <map>#include <set>#include <list>#include <cmath>#include <deque>#include <queue>#include <stack>#include <bitset>#include <ccty原创 2015-08-23 00:22:11 · 1109 阅读 · 0 评论 -
UVALive - 3983 - Robotruck (DP+单调队列)
Robotruck题目传送:UVALive - 3938 - RobotruckAC代码:#include <map>#include <set>#include <list>#include <cmath>#include <deque>#include <queue>#include <stack>#include <bitset>#include <cctype>#inclu原创 2015-09-04 21:39:09 · 862 阅读 · 0 评论 -
DP简单题
The Triangle题目传送:The TriangleTLE代码(递归形式的DP):#include <map>#include <set>#include <cmath>#include <deque>#include <queue>#include <stack>#include <cstdio>#include <cctype>#include <string>#incl原创 2015-07-29 15:30:39 · 629 阅读 · 0 评论 -
蓝桥杯 - 概率计算 (概率DP)
题目传送:蓝桥杯 - 概率计算概率计算 时间限制:1.0s 内存限制:256.0MB锦囊1锦囊2锦囊3问题描述 生成n个∈[a,b]的随机整数,输出它们的和为x的概率。输入格式 一行输入四个整数依次为n,a,b,x,用空格分隔。输出格式 输出一行包含一个小数位和为x的概率,小数点后保原创 2015-05-19 13:00:48 · 3464 阅读 · 1 评论 -
HDU - 1003 - Max Sum && POJ - 1050 - To the Max (经典DP问题)
题目传送:HDU - 1003思路:最大子序列和dp[i]= a[i] (dp[i-1]dp[i]= dp[i-1]+a[i] (dp[i-1]>=0)AC代码:#include #include #include #include #include #include #include #include #include #includ原创 2015-05-07 00:41:27 · 749 阅读 · 0 评论 -
UVA - 674 - Coin Change (背包型DP)
UVA - 674Coin ChangeTime Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %lluSubmit StatusDescriptionSuppose there are 5 types of coins: 50-原创 2015-03-25 16:25:28 · 866 阅读 · 0 评论 -
UVA - 103 - Stacking Boxes (动态规划)
UVA - 103Stacking BoxesTime Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %lluSubmit StatusDescriptionBackgroundSome concepts in Mathe原创 2015-03-31 23:24:27 · 668 阅读 · 0 评论 -
UVA - 10130 - SuperSale (动态规划 - 01背包)
10130 SuperSaleThere is a SuperSale in a SuperHiperMarket. Every person can take only one object of each kind, i.e.one TV, one carrot, but for extra low price. We are going with a whole family to原创 2015-03-22 10:24:56 · 1174 阅读 · 0 评论 -
UVA - 357 - Let Me Count The Ways (动态规划)
UVA - 357Let Me Count The WaysTime Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %lluSubmit StatusDescriptionAfter making a purchase at a原创 2015-03-15 17:44:12 · 630 阅读 · 0 评论 -
Codeforces Round #293 (Div. 2) -- D. Ilya and Escalator (DP)
D. Ilya and Escalatortime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputIlya got tired of sports programming,原创 2015-02-25 13:34:47 · 676 阅读 · 0 评论 -
hihoCoder - 1037 - 数字三角形 (动态规划)
#1037 : 数字三角形时间限制:10000ms单点时限:1000ms内存限制:256MB问题描述小Hi和小Ho在经历了螃蟹先生的任务之后被奖励了一次出国旅游的机会,于是他们来到了大洋彼岸的美国。美国人民的生活非常有意思,经常会有形形色色、奇奇怪怪的活动举办,这不,小Hi和小Ho刚刚下飞机,就赶上了当地的迷宫节活动。迷宫节里展览出来的迷原创 2015-02-03 13:39:15 · 1078 阅读 · 0 评论 -
hihoCoder - 1038 - 01背包 (经典动态规划问题!!)
#1038 : 01背包时间限制:20000ms单点时限:1000ms内存限制:256MB描述且说上一周的故事里,小Hi和小Ho费劲心思终于拿到了茫茫多的奖券!而现在,终于到了小Ho领取奖励的时刻了!小Ho现在手上有M张奖券,而奖品区有N件奖品,分别标号为1到N,其中第i件奖品需要need(i)张奖券进行兑换,同时也只能兑换一次,为了原创 2014-12-25 18:53:45 · 1144 阅读 · 0 评论 -
NYOJ - 715 - Adjacent Bit Counts --第六届河南省程序设计大赛 (DP!!)
Adjacent Bit Counts时间限制:1000 ms | 内存限制:65535 KB难度:4描述For a string of n bits x1, x2, x3, …, xn, the adjacent bit count of the string is given by fun(x) = x1*x2 + x2*x3 + x3*x 4 + … +原创 2014-12-26 10:51:51 · 1174 阅读 · 0 评论 -
NYOJ - 716 - River Crossing --第六届河南省程序设计大赛 (简单DP!!)
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 available for transpo原创 2014-12-26 10:15:27 · 1206 阅读 · 0 评论 -
HDU-1203-I NEED A OFFER! (简单DP!)
I NEED A OFFER!Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 17099 Accepted Submission(s): 6831Problem DescriptionSpeakless原创 2014-11-22 15:16:25 · 654 阅读 · 0 评论 -
ZOJ - 3623 - Battle Ships (01背包变形)
Battle ShipsTime Limit: 2 Seconds Memory Limit: 65536 KBBattle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a defense tower, which has L longevity.原创 2015-03-25 21:00:46 · 685 阅读 · 0 评论 -
UVA - 10003 - Cutting Sticks (区间DP)
这里简述一下区间DP:主要思想:区间动态规划问题一般都是考虑对于每段区间,他们的最优值都是由几段更小区间的最优值得到,是分治思想的一种应用,将一个区间问题不断划分为更小的区间直至一个素组成的区间,枚举他们的组合,求合并后的最优值。定义状态:设dp[i][j]为区间i,j之间的最小代价(实际看题意)实现过程:for(int p = 1 ; p //p是区间的长度,作为阶段原创 2015-03-24 23:18:14 · 756 阅读 · 0 评论 -
UVA - 624 - CD (动态规划)
UVA - 624CDTime Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %lluSubmit StatusDescriptionYou have a long drive by car ahead. You have a t原创 2015-03-22 11:26:59 · 1270 阅读 · 0 评论 -
URAL - 1009 - K-based Numbers (简单DP)
1009. K-based NumbersTime limit: 1.0 secondMemory limit: 64 MBLet’s consider K-based numbers, containing exactly N digits. We define a number to be valid if itsK-based notation doesn’t c原创 2015-03-29 21:03:35 · 585 阅读 · 0 评论 -
蓝桥杯 - 买不到的数目 (动态规划 + 数论)
历届试题 买不到的数目 时间限制:1.0s 内存限制:256.0MB 问题描述小明开了一家糖果店。他别出心裁:把水果糖包成4颗一包和7颗一包的两种。糖果不能拆包卖。小朋友来买糖的时候,他就用这两种包装来组合。当然有些糖果数目是无法组合出来的,比如要买 10 颗糖。你可以用计算机测试一下,在这种包装情况下,最大不能买到的数量原创 2015-03-21 15:14:33 · 2806 阅读 · 2 评论 -
SGU - 104 - Little shop of flowers (动态规划)
104. Little shop of flowerstime limit per test: 0.25 sec. memory limit per test: 4096 KBPROBLEMYou want to arrange the window of your flower shop in a most pleasant way. You have F b原创 2015-03-16 10:58:37 · 894 阅读 · 1 评论 -
UVA - 562 - Dividing coins (01背包)
UVA - 562Dividing coinsTime Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %lluSubmit StatusDescriptionIt's commonly known that the Dutch h原创 2015-03-25 18:43:09 · 775 阅读 · 0 评论 -
HDU - 1114 - Piggy-Bank (完全背包)
Piggy-BankTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13822 Accepted Submission(s): 7000Problem DescriptionBefore ACM can原创 2015-03-25 17:05:30 · 738 阅读 · 0 评论 -
UVA - 111 - History Grading (LCS)
UVA - 111History GradingTime Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %lluSubmit StatusDescriptionBackgroundMany problems in Comput原创 2015-03-15 20:36:59 · 693 阅读 · 0 评论 -
HDU - 1248 - 寒冰王座 (完全背包 or 贪心)
寒冰王座Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12267 Accepted Submission(s): 6221Problem Description不死族的巫妖王发工资拉,死亡骑士拿到一张原创 2015-03-15 22:50:50 · 810 阅读 · 0 评论