![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
线性DP
文章平均质量分 84
键盘里的青春
加油~
展开
-
ZOJ 1074 To the Max(最大子矩阵和)【java】
ProblemGiven a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1 x 1 or greater located within the whole array. The sum of a rectangle is t...原创 2018-05-24 14:21:45 · 445 阅读 · 0 评论 -
1241 特殊排列 (思维)
1241 特殊的排序题目来源: 摩根斯坦利的比赛题基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题一个数组的元素为1至N的整数,现在要对这个数组进行排序,在排序时只能将元素放在数组的头部或尾部,问至少需要移动多少个数字,才能完成整个排序过程?例如:2 5 3 4 1 将1移到头部 => 1 2 5 3原创 2017-05-01 11:53:11 · 540 阅读 · 0 评论 -
DP经典 ----- 整数划分
整数划分 --- 一个老生长谈的问题: 1) 练练组合数学能力. 2) 练练递归思想 3) 练练DP 总之是一道经典的不能再经典的题目: 这道好题求: 1. 将n划分成若干正整数之和的划分数。 2. 将n划分成k个正整数之和的划分数。 3. 将n划分成最大数不超过k的划分数。 4. 将n划分成若干奇正整数之和的划分数。 5. 将n划分成若转载 2017-02-23 12:35:54 · 1260 阅读 · 0 评论 -
☆URAL 2018 The Debut Album (dp 两种写法)
2018. The Debut AlbumTime limit: 2.0 secondMemory limit: 64 MBPop-group “Pink elephant” entered on recording their debut album. In fact they have only two songs: “My love” and “I miss yo原创 2017-04-30 16:24:57 · 497 阅读 · 0 评论 -
codevs 1043 方格取数 (dfs or dp)
题目描述 Description设有N*N的方格图(N 某人从图的左上角的A 点出发,可以向下行走,也可以向右走,直到到达右下角的B点。在走过的路上,他可以取走方格中的数(取走后的方格中将变为数字0)。此人从A点到B 点共走两次,试找出2条这样的路径,使得取得的数之和为最大。 输入描述 Input Description输入的第一行为一个整数N(原创 2017-04-05 11:58:58 · 761 阅读 · 0 评论 -
uva11400Lighting System Design(简单DP+贪心)
题目大意:有一个照明系统需要用到n种灯,每种灯的电压为V,电源费用K,每个灯泡费用为C,需要该灯的数量为L。注意到,电压相同的灯泡只需要共享一个对应的电源即可,还有电压低的灯泡可以被电压高的灯泡替代。为了节约成本,你将设计一种系统,使之最便宜。分析:首先需要明确一种灯泡要么全部换,要么不换。如果换一部分的话,首先电源费用得不到节约,那么节约的部分就只来自于换的那部分灯泡,既然可以节约钱干嘛不干原创 2017-03-15 11:07:45 · 740 阅读 · 2 评论 -
★UVa 1025---A Spy in the Metro 题解 (简单dp)
https://vjudge.net/problem/UVA-1025题意:一个间谍要从第一个车站到第n个车站去会见另一个,在是期间有n个车站,有来回的车站,让你恰好在时间T到达n,并且等车时间最短,输出最短等车时间。思路:先用一个L[][]来表示在t时刻,在车站i,是否有往右开的车。同理,R[][]用来保存是否有往左开的车。 用d(i,j)表示时刻i,你在原创 2017-03-15 10:58:48 · 1193 阅读 · 0 评论 -
☆UVALive 7276 Wooden Signs (DP or 记忆化搜索)
题意:摆木图, 一共n层木头,告诉你第一个木头尾端跟头端的位置,其余n-1层头端的位置,组合方法是,上面图的方法。。。要么尾端跟尾端一起,要么尾端跟头端一起(必须有一定长度的木头支撑,具体看图)思路:递推代码:#include #include #include #include using namespace std;typedef long long ll;const原创 2017-03-31 13:31:37 · 561 阅读 · 0 评论 -
bzoj 3398 [Usaco2009 Feb]Bullcow 牡牛和牝牛 (dp+前缀)
3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 208 Solved: 140[Submit][Status][Discuss]Description 约翰要带N(1≤N≤100000)只牛去参加集会里的展示活动,这些牛可以是牡牛,也可以是牝牛.原创 2017-03-31 13:17:52 · 421 阅读 · 0 评论 -
HDU 3664 Permutation Counting (DP)
Permutation CountingTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 493 Accepted Submission(s): 258Problem DescriptionG原创 2017-03-31 10:58:16 · 329 阅读 · 0 评论 -
codevs 2033 邮票 (背包)&& codevs 1047 邮票面值设计 (dfs+dp)
题目描述 Description已知一个 N 枚邮票的面值集合(如,{1 分,3 分})和一个上限 K —— 表示信封上能够贴 K 张邮票。计算从 1 到 M 的最大连续可贴出的邮资。例如,假设有 1 分和 3 分的邮票;你最多可以贴 5 张邮票。很容易贴出 1 到 5 分的邮资(用 1 分邮票贴就行了),接下来的邮资也不难:6 = 3 + 3 7 = 3 + 3 + 1 8原创 2017-04-06 16:52:21 · 605 阅读 · 0 评论 -
ZOJ 3872 Beauty of Array (思维 dp思想)
D - Beauty of ArrayTime Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %lluSubmit Status Practice ZOJ 3872DescriptionEdward has an array A with N integers. He defin原创 2017-05-01 20:25:30 · 448 阅读 · 0 评论 -
1084 矩阵取数问题 V2 -
#include #include #include #include using namespace std;const int maxn = 205;int dp[maxn*2][maxn][maxn], a[maxn][maxn];int main(){ int n, m; scanf("%d%d", &m, &n); for(int i = 1; i原创 2017-05-01 22:54:30 · 501 阅读 · 0 评论 -
图论姿势总结
Elegant ConstructionTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1081 Accepted Submission(s): 562Special JudgeProblem Descript原创 2017-09-06 11:35:17 · 499 阅读 · 0 评论 -
线性DP做题整合
1065 最小正子段和基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 收藏 关注N个整数组成的序列a[1],a[2],a[3],…,a[n],从中选出一个子序列(a[i],a[i+1],…a[j]),使这个子序列的和>0,并且这个和是所有和>0的子序列中最小的。例如:4,-1,5,-2,-1,2,6,-2。-1,5,-2,-1,序列和为1,是最小的。...原创 2017-02-24 14:11:14 · 1264 阅读 · 0 评论 -
HDU 1513 Palindrome (滚动数组lcs,水)
雷火盘古校园招聘开始!PalindromeTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6427 Accepted Submission(s): 2123Problem Descrip原创 2017-09-03 16:06:11 · 368 阅读 · 0 评论 -
HDU 1423 && ZOJ 2432 (LCIS模板)
定义状态F[i][j]表示以a串的前i个整数与b串的前j个整数且以b[j]为结尾构成的LCIS的长度。状态转移方程:①F[i][j] = F[i-1][j] (a[i] != b[j])②F[i][j] = max(F[i-1][k]+1) (1 b[k])现在我们来说为什么会是这样的状态转移方程呢?对于①,因为F[i][j]是以b[j]为结尾的L原创 2017-08-29 00:13:24 · 838 阅读 · 0 评论 -
HDU 6170 Two strings (二维DP)
Two stringsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 626 Accepted Submission(s): 245Problem DescriptionGiving two strin原创 2017-08-23 01:08:19 · 368 阅读 · 0 评论 -
51nod 1202 子序列个数 (子序列套路dp)&& HDU 5791 Two (两串求相同子序列)
1202 子序列个数题目来源: 福州大学 OJ基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 收藏 关注子序列的定义:对于一个序列a=a[1],a[2],......a[n]。则非空序列a'=a[p1],a[p2]......a[pm]为a的一个子序列,其中1例如4,14,2,3和14,1,原创 2017-07-16 00:08:12 · 607 阅读 · 0 评论 -
HDU - 5773 The All-purpose Zero(思维+LIS)
The All-purpose ZeroTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2427 Accepted Submission(s): 1099Problem Description?? ge原创 2017-09-04 01:43:35 · 371 阅读 · 0 评论 -
SDUT 3565 Feed the monkey && sdut 2879 Colorful Cupcakes (dp)
Feed the monkeyTime Limit: 2000MS Memory Limit: 131072KBSubmit Statistic DiscussProblem DescriptionAlice has a monkey, she must feed fruit to the monkey every day.She has three kinds o原创 2017-05-01 00:08:29 · 557 阅读 · 0 评论 -
codevs 1959 拔河比赛
题目描述 Description一个学校举行拔河比赛,所有的人被分成了两组,每个人必须(且只能够)在其中的一组,要求两个组的人数相差不能超过1,且两个组内的所有人体重加起来尽可能地接近。输入描述 Input Description数据的第1行是一个n,表示参加拔河比赛的总人数,n输出描述 Output Description包含两个整原创 2017-04-21 21:00:39 · 930 阅读 · 0 评论 -
ural 2072 - Kirill the Gardener 3 详细题解 (思维+dp)
2072. Kirill the Gardener 3Time limit: 2.0 secondMemory limit: 64 MBKirill the gardener has got a new task. He has to water the flowers growing on the huge flowerbed! It should be mentio原创 2017-03-23 15:49:23 · 1550 阅读 · 0 评论 -
HDU 2844 Coins (多重背包)
CoinsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 13004 Accepted Submission(s): 5208Problem DescriptionWhuacmers use coins原创 2016-11-17 21:45:59 · 812 阅读 · 0 评论 -
FZU 1432 Problem 1432 Coin Changing(多重背包变形DP)
Problem 1432 Coin ChangingAccept: 358 Submit: 1017Time Limit: 1000 mSec Memory Limit : 32768 KB Problem DescriptionThere are n kinds of coins. Given the available number of coins原创 2016-11-17 22:49:15 · 579 阅读 · 0 评论 -
LCS,LIS等模板
咳咳,有一部分是根据CillyB总结的1.最大子序和最大子序列和一定是连续的,如果不连续,就没有意义了,因为我们只需要扫描一遍数组,输出其中所有正整数即可,他们的和一定是最大的。很容易理解时间界O(N) 是正确的,但是要是弄明白为什么正确就比较费力了。其实这个是算法二的一个改进。分析的时候也是i代表当前序列的起点,j代表当前序列的终点。如果我们不需要知道最佳子序列的位置原创 2016-11-16 15:12:08 · 606 阅读 · 0 评论 -
BestCoder Round #89 1002 && HDU 5945 详解(单调队列+DP)加一种错误的方法
Fxx and game Accepts: 74 Submissions: 1857 Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)问题描述青年理论计算机科学家Fxx给的学生设计了一款数字游戏。一开始你将会得到原创 2016-11-08 18:23:32 · 831 阅读 · 2 评论 -
HDU 1069 Monkey and Banana (经典dp)详解及易错点分析
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原创 2016-08-19 13:08:41 · 1117 阅读 · 0 评论 -
HDU 1269 Tickets(水题)
题意:有k个人要买票(你也在里面最后一位),每个人买票要花时间,或者两个相邻的人一起买会有一个时间, 问你最少花费多少时间才能买到票思路:算是dp里面很水的一题了。 状态转移方程是:dp[i] = min(dp[i-1]+单独买花的时间, dp[i-2]+和前面那个人一起买花的时间) 初始状态是dp[1] = 第一个人单独买话的时间,方程也比较好找。Desc原创 2016-08-18 20:46:52 · 447 阅读 · 0 评论 -
HDU 1078 FatMouse and Cheese(dp+记忆化搜索)史上最详细题解
题意:给定一幅图,每个点有一定权值,现在有一只老鼠在起始点(0,0),他能水平或者垂直移动1~k格之后,停在某点并获得权值,而且每次移动后所在的点,都要比刚离开的那个点的权值更大,求最多能获得多少权值。思路:第一次做记忆化搜索题目,一开始用纯dp做的,找出了所谓状态转移方程,连样例都过不了,一直debug,还以为是哪里写错了,百度了一发,知道了原来要用记忆化搜索,顿时豁然开朗,也知道了为什么纯原创 2016-08-18 19:24:06 · 1086 阅读 · 3 评论 -
HDU 2571命运(有dp思想的模拟水题)
讲道理,这一题真的不难,因为最近在搞基础dp,就用dp思想写了,感觉数据量比较小dfs应该可以;这题用dp思想写的话,思想无非就是:每行每一列的格子都可以从1,他的因子过来,2,左面的一个格子过来,3,上面过来,那就选出从这三个方向来的最大值,再加上当前格子的值,每一个格子的dp都代表从起点到这个格子的最大值,如果你会LIS,这个题一眼就应该会了,只不过把一行上面的数据变成了n行而已,但是,但是,原创 2016-08-18 10:10:18 · 576 阅读 · 0 评论 -
BZOJ 4300 绝世好题(DP)
4300: 绝世好题Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1423 Solved: 741[Submit][Status][Discuss]Description给定一个长度为n的数列ai,求ai的子序列bi的最长长度,满足bi&bi-1!=0(2Input输入文件共2行。第一行包括一个整原创 2016-11-21 17:03:14 · 616 阅读 · 0 评论 -
HDU 2589 Phalanx(dp找最大对称矩形)细节及算法详解
PhalanxTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1220 Accepted Submission(s): 597Problem DescriptionToday is army day, but原创 2016-08-20 10:47:10 · 1021 阅读 · 0 评论 -
lightoj 1036 A Refining Company(矩形dp)
1036 - A Refining Company PDF (English)StatisticsForumTime Limit: 3 second(s)Memory Limit: 32 MBIts year 2200, planet Earth is out of resources and原创 2016-11-21 17:09:53 · 557 阅读 · 0 评论 -
COdedorce 366 C Dima and Salad 题解(隐形01背包,好题)
C. Dima and Saladtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputDima, Inna and Seryozha have gathered in a原创 2017-03-08 15:32:24 · 1456 阅读 · 0 评论 -
Lightoj - 1017 - Brush (III) 详解(经典线性DP)
1017 - Brush (III) PDF (English)StatisticsForumTime Limit: 2 second(s)Memory Limit: 32 MBSamir returned home from the contest and got angry after seei原创 2017-01-25 00:34:03 · 610 阅读 · 0 评论 -
☆lightoj1013 Love Calculator 两种转移方程详解(LCS+方案数DP)
1013 - Love Calculator PDF (English)StatisticsForumTime Limit: 2 second(s)Memory Limit: 32 MBYes, you are developing a 'Love calculator'. The software原创 2017-01-19 17:44:55 · 687 阅读 · 0 评论 -
lightoj 1047 - Neighbor House DP(简单线性DP)
1047 - Neighbor House PDF (English)StatisticsForumTime Limit: 0.5 second(s)Memory Limit: 32 MBThe people of Mohammadpur have decided to paint each of原创 2017-01-17 23:44:25 · 533 阅读 · 0 评论 -
Codeforces 766 C Mahmoud and a Message 详解(DP)
C. Mahmoud and a Messagetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputMahmoud wrote a message s of lengt原创 2017-02-16 16:31:21 · 693 阅读 · 1 评论 -
codeforces 429B B. Working out 详解(dp)
D. Working outtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputSummer is coming! It's time for Iahub and Iahubina t原创 2017-01-16 22:27:41 · 1695 阅读 · 0 评论