
动态规划(DP)
各种DP
deebcjrb
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
【每日一题】9月9日题目精讲-Working out
其实这个倒着想就行,从一个点出发到四个角的距离最大,正好还不用处理自己本身的值,如果正常思维的话会很麻烦并且不会写。。。一共两种情况,ans两种判断方式。设四个数组分别表示到四个角的最大距离#include<iostream>#include<string>#include<math.h>#include<algorithm>#include<vector>//#include<bits/stdc++.h>typede原创 2020-09-11 22:42:55 · 113 阅读 · 0 评论 -
【每日一题】8月4日题目精讲—购物 (背包问题)
https://ac.nowcoder.com/acm/problem/14526首先我们每天肯定都是按照价格从低到高买糖果,所以决策只需要关注当前天买了多少个。f[i][j]代表前i天已经买了j颗糖果的最小花费,枚举第i天买了多少糖果。f[i][j] = min(f[i-1][k] + sum[i][i-k] + (j-k)*(j-k)); (k从i-m到i-1枚举)#include<iostream>#include<string>#include<mat原创 2020-08-19 22:30:56 · 150 阅读 · 0 评论 -
【每日一题】7月28日题目精讲—涂色PAINT
https://ac.nowcoder.com/acm/problem/19909f[i][j]表示把i到j的区间涂好的最少次数当i和j颜色一样——可以认为i是涂[i+1,j]的时候顺便涂上的,或者j是涂[i,j-1]的时候顺便涂上的。所以f[i][j]= min(f[i+1][j], f[i][j-1])i和j颜色不一样:枚举断点——f[i][j]=min(f[i][j],f[i][k]+f[k+1][j])#include<iostream>#include<strin原创 2020-08-11 23:33:05 · 233 阅读 · 0 评论 -
删括号 (牛客DP三星题)
https://ac.nowcoder.com/acm/problem/21303定义dp[i][j][k],dp是bool类型即可,表示序列s在前i个并且删除掉k个左括号 ‘(’ 的情况下,可以与序列t的前j个匹配,如果删除了一个括号对,那么k就要相应的减一,所以最终判断的条件就是dp[len1][len2][0]是否为0,就是表示在恰好删除若干括号对的情况下相匹配。一共只有四种情况if(s[i+1]=='('&&t[i+1]=='(') dp[i+1][j+1][k]=原创 2020-07-27 21:30:20 · 424 阅读 · 1 评论 -
数学考试 【每日一题】3月27日题目精讲 前缀和、动态规划
https://ac.nowcoder.com/acm/problem/15553因为长度已知,最暴力的办法肯定是直接枚举两个子区间的起点,然后求和,复杂度O(n2k)O(n^{2} k)O(n2k)。连续区间求和可以用前缀和来优化,即用 sum[i]{sum[i]}sum[i]表示数列前 i{i}i 个数字的和,那么sum[i]=sum[i−1]+a[i]{sum[i]= sum[i-1...原创 2020-04-17 20:22:42 · 139 阅读 · 0 评论 -
最大子阵(DP+前缀和)
给定一个n*m的矩阵A,求A中的一个非空子矩阵,使这个子矩阵中的元素和最大。其中,A的子矩阵指在A中行和列均连续的一块。输入输入的第一行包含两个整数n, m,分别表示矩阵A的行数和列数。接下来n行,每行m个整数,表示矩阵A。1<=n, m<=500,A中每个元素的绝对值不超过5000。输出输出一行,包含一个整数,表示A中最大的子矩阵中的元素和。样例输入 Cop...原创 2020-03-18 20:50:31 · 230 阅读 · 0 评论 -
夺宝奇兵(记忆化搜索)
在一座山上,有很多很多珠宝,它们散落在山底通往山顶的每条道路上,不同道路上的珠宝的数目也各不相同.下图为一张藏宝地图: 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 ”夺宝奇兵”从山下出发,到达山顶,如何选路才能得到最多的珠宝呢?在上图所示例子中,按照5->7->8->3->7的顺序,将得到最大值30[输入] 第一行正整数N(10...原创 2020-03-02 19:40:01 · 190 阅读 · 0 评论 -
牛客寒假算法基础集训营2(G 处女座与复读机 )(DP||DFS||模拟)
https://ac.nowcoder.com/acm/contest/327/G三种方法dfs实现(完全没想到这个还能dfs)#include<bits/stdc++.h>using namespace std;string s1, s2;bool flag; void dfs(int a, int b, int c) { if (c > 2)...原创 2020-01-17 00:14:36 · 167 阅读 · 0 评论 -
Remove One Element(一般DP)
You are given an array aa consisting of nn integers.You can remove at most one element from this array. Thus, the final length of the array is n−1n−1 or nn .Your task is to calculate the maximum p...原创 2020-01-16 18:07:29 · 363 阅读 · 0 评论 -
Three displays(基础DP)
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.There are nn displays pl...原创 2020-01-14 23:44:53 · 331 阅读 · 0 评论 -
被3整除的子序列 (牛客2星题)(线性DP)
题目:给你一个长度为50的数字串,问你有多少个子序列构成的数字可以被3整除(输入一个字符串,由数字构成,长度小于等于50)答案对1e9+7取模样例1:输入:132 输出:3样例2:输入:123456 输出:23首先要知道被三整除的数字的特征 只要所有数位数字的和可以被三整出即可。因此可以把字符串每个数字取模3 处理成 只有0 1 2三个字符的串。二维数组dp[...原创 2019-12-30 00:50:15 · 458 阅读 · 1 评论 -
最大区间和(基础DP)
给你一个数组,让你求从一个从i到j和最大的这么一个范围,策略是:每输入第i个数要去判断要不要把这个数加入我前面所组成的数组x[i-1]里, 如果加入这个数后得到和不小于这个数,那就把这个数加入前面的数列,否则重新开始构建最大和的数列。 用两个数组x[i]存max(x[i]+a,a),x1[i]存处理每一个数时开始的位置例如:输入 5 6 -1 5 4 7时 6 -1...原创 2019-12-29 22:58:58 · 1725 阅读 · 0 评论 -
Round Numbers(poj3252)(组合数学||数位DP)
原题目:DescriptionThe cows, as you know, have no fingers or thumbs and thus are unable to play Scissors, Paper, Stone' (also known as 'Rock, Paper, Scissors', 'Ro, Sham, Bo', and a host of other name...原创 2019-10-25 23:02:22 · 164 阅读 · 0 评论 -
(kuangbin带你飞--区间DP)Coloring Brackets
原题目:Once Petya read a problem about a bracket sequence. He gave it much thought but didn't find a solution. Today you will face it.You are given string s. It represents a correct bracket sequence....原创 2019-08-28 14:23:09 · 196 阅读 · 0 评论 -
Kejin Player (概率DP)hdu6656
原题目:Cuber QQ always envies those Kejin players, who pay a lot of RMB to get a higher level in the game. So he worked so hard that you are now the game designer of this game. He decided to annoy thes...原创 2019-08-16 17:52:30 · 210 阅读 · 0 评论 -
Race to 1 Again(概率DP)
原题目:Rimi learned a new thing about integers, which is - any positive integer greater than 1 can be divided by its divisors. So, he is now playing with this property. He selects a number N. And he ca...原创 2019-08-16 11:04:47 · 188 阅读 · 0 评论 -
Multiplication Puzzle (区间DP)
原题目:The 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 points equal to ...原创 2019-08-01 17:38:56 · 164 阅读 · 0 评论 -
Discovering Gold (概率DP)
部分摘自:https://www.cnblogs.com/daydayupacm/p/5788115.html原题目:You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell of the cave can contain any amount of gold.Initi...原创 2019-08-15 20:15:40 · 198 阅读 · 0 评论 -
(kuangbin带你飞--基础DP)Milking Time poj3616
原题目:Bessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that she decides to schedule her nextN(1 ≤N≤ 1,000,000) hours (conveniently labeled 0..N-1) so th...原创 2019-08-06 21:26:53 · 222 阅读 · 0 评论 -
(kuangbin带你飞--基础DP)Phalanx hdu2859(最大对称矩阵)
原题目:Today is army day, but the servicemen are busy with the phalanx for the celebration of the 60th anniversary of the PRC.A phalanx is a matrix of size n*n, each element is a character (a~z or A~Z...原创 2019-08-06 18:04:10 · 187 阅读 · 0 评论 -
(Kuangbin带你飞--基础DP ) Ignatius and the Princess IV
原题目:"OK, you are not too bad, em... But you can never pass the next test." feng5166 says."I will tell you an odd number N, and then N integers. There will be a special integer among them, you have ...转载 2019-08-03 18:26:01 · 113 阅读 · 0 评论 -
Brackets poj(区间DP)
原题目:We 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 regula...原创 2019-07-31 14:33:15 · 203 阅读 · 0 评论 -
(kuangbin带你飞--基础DP)Monkey and Banana HDU1609
原题目:A 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 blocks. If th...原创 2019-08-04 22:30:08 · 266 阅读 · 0 评论 -
Cutting Sticks (区间DP)(区间DP递推详解)
原题目:You have to cut a wood stick into pieces. The most affordable company, The Analog Cutting Machinery, Inc. (ACM), charges money according to the length of the stick being cut. Their procedure of w...原创 2019-07-31 20:22:47 · 288 阅读 · 0 评论 -
(kuangbin带你飞--基础DP)Super Jumping! Jumping! Jumping! HDU 1087
原题目:Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.The ...转载 2019-08-04 23:34:04 · 130 阅读 · 0 评论 -
(kuangbin带你飞--基础DP)免费馅饼 HDOJ 1176
原题目:都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼。说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内。馅饼如果掉在了地上当然就不能吃了,所以gameboy马上卸下身上的背包去接。但由于小径两侧都不能站人,所以他只能在小径上接。由于gameboy平时老呆在房间里玩游戏,虽然在游戏中是个身手敏捷的高手,但在现实中运动...原创 2019-08-05 15:58:02 · 109 阅读 · 0 评论 -
(kuangbin带你飞--基础DP)Tickets HDU1260
原题目:Jesus, what a great movie! Thousands of people are rushing to the cinema. However, this is really a tuff time for Joe who sells the film tickets. He is wandering when could he go back home as ea...原创 2019-08-05 19:56:29 · 177 阅读 · 0 评论 -
(kuangbin带你飞--基础DP)最少拦截系统 HDU1257
原题目:某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹.怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少...原创 2019-08-05 20:35:18 · 177 阅读 · 0 评论 -
(kuangbin带你飞--基础DP)Help Jimmy poj1661
原题目:"Help Jimmy" 是在下图所示的场景上完成的游戏。场景中包括多个长度和高度各不相同的平台。地面是最低的平台,高度为零,长度无限。Jimmy老鼠在时刻0从高于所有平台的某处开始下落,它的下落速度始终为1米/秒。当Jimmy落到某个平台上时,游戏者选择让它向左还是向右跑,它跑动的速度也是1米/秒。当Jimmy跑到平台的边缘时,开始继续下落。Jimmy每次下落的高度不能超...原创 2019-08-05 21:37:42 · 147 阅读 · 0 评论 -
四边形不等式优化(区间DP)例题_石子合并问题
在动态规划中,经常遇到形如下式的状态转移方程: m(i,j)=min{m(i,k-1),m(k,j)}+w(i,j)(i≤k≤j)(min也可以改为max) 上述的m(i,j)表示区间[i,j]上的某个最优值。w(i,j)表示在转移时需要额外付出的代价。该方程的时间复杂度为O(N3) 下面我们通过四边形不等式来优化上述方程,首先介绍什么是“区间包含的单调性”和“四边...原创 2019-08-01 18:27:05 · 269 阅读 · 0 评论 -
Monkey Party HDU 3506(区间DP+四边不等式优化)
原题目:Far away from our world, there is a banana forest. And many lovely monkeys live there. One day, SDH(Song Da Hou), who is the king of banana forest, decides to hold a big party to celebrate Crazy...原创 2019-08-01 18:56:00 · 160 阅读 · 0 评论 -
(kuangbin带你飞--基础DP)Jury Compromise poj1015
原题目:In Frobnia, a far-away country, the verdicts in court trials are determined by a jury consisting of members of the general public. Every time a trial is set to begin, a jury has to be selected, ...原创 2019-08-06 11:25:36 · 173 阅读 · 0 评论 -
Anniversary party (树状DP)
原题目:There is going to be a party to celebrate the 80-th Anniversary of the Ural State University. The University has a hierarchical structure of employees. It means that the supervisor relation form...原创 2019-08-01 23:56:45 · 171 阅读 · 0 评论 -
Strategic Game (树形DP)
原题目:Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must defend a m...原创 2019-08-02 10:49:38 · 220 阅读 · 0 评论 -
(kuangbin带你飞--基础DP)Treats for the Cows poj3186(区间DP)
原题目:FJ has purchased N (1 <= N <= 2000) yummy treats for the cows who get money for giving vast amounts of milk. FJ sells one treat per day and wants to maximize the money he receives over a g...原创 2019-08-06 14:56:01 · 216 阅读 · 0 评论 -
Tree of Tree (树形DP)
原题目:You're given a tree with weights of each node, you need to find the maximum subtree of specified size of this tree.Tree Definition A tree is a connected graph which contains no cycles.In...原创 2019-08-02 11:47:20 · 390 阅读 · 0 评论 -
(kuangbin带你飞--基础DP)FatMouse and Cheese hdu1078(记忆化搜索)
原题目: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 g...原创 2019-08-06 16:52:38 · 172 阅读 · 0 评论 -
(kuangbin带你飞--基础DP)Max Sum Plus Plus
原题目:Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem....原创 2019-08-02 22:15:50 · 127 阅读 · 0 评论