
区间DP
涉及区间更新的DP
为什么他们cf写的这么快
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
cf1509 C. The Sports Festival(区间DP)
题目链接题意:给定一个数组,定义di=max(a1,a2,a3…ai)-min(a1,a2,a3…ai),求d1+d2+d3+。。。。dn的最小值。思路:看到这个n的范围就应该往DP方面想,但怎奈在贪心的道路上一去不复返。。。先将数组排序,我们先考虑小范围的情况。比如我选了a【x】,那么如果要再选选一个的话肯定考虑a【x-1】或a【x+1】,不然你选择了a【x+2】的话就是让最大值又更大了,显然不满足局部最优。于是乎我们定义dp【l】【r】是a数组中区间【l,r】范围内的数已经放好了,如果再放一个数原创 2021-05-05 21:57:09 · 362 阅读 · 0 评论 -
CROC-MBTU 2012, Elimination Round (ACM-ICPC) H. Queries for Number of Palindromes(区间DP+容斥)
题目链接题意:给定一个字符串和m次查询,每次查询给出l,r,问区间【l,r】内的回文子串的个数。思路:dp【l,r】代表【l,r】内的回文子串个数,vis【l,r】代表区间【l,r】是否能组成回文串,这里计数的时候有点容斥的思路,具体看转移代码。#include<bits/stdc++.h>using namespace std;typedef long long ll;...原创 2020-04-29 21:58:23 · 169 阅读 · 0 评论 -
Codeforces Round #256 (Div. 2) C. Painting Fence(区间DP+记忆化)
题目链接题意:给你一个栅栏,长度不等,宽度为1,用一个宽为1的刷子刷,最少刷几次;思路:竖着刷的时候答案肯定是r-l+1,关键是看横着刷的时候,dp【l】【r】代表刷【l,r】横着刷的最小次数。这里注意一下我们横着刷的时候只能刷高度最小的那个,否则就不满足题意了,所以每次区间dfs的时候要找minn。#include<bits/stdc++.h>using namespace...原创 2020-04-29 21:54:24 · 238 阅读 · 0 评论 -
cf 39 C. Moon Craters(*)
题目链接题意:给出n个圆心在x轴上的圆的圆心横坐标和半径,要求从其中选出尽可能多的圆使得任意两圆只能是相邻、相切或包含,问最多可以选出多少圆满足条件思路:题意转化一下,问题转化为给出nn个区间,选取尽可能多的区间使得所选任意两个区间不能相交,把区间端点离散化变成mm个端点,记录每个端点作为左端点时对应的右端点集合,以dp[i][j]dp[i][j]表示ii端点到jj端点可以选的圆的最大数量,...原创 2020-04-29 21:50:27 · 236 阅读 · 0 评论 -
Tinkoff Challenge - Elimination Round D. Presents in Bankopolis(区间DP+记忆化搜索)
题目链接题意:感觉又是个阅读理解题。。。现在给你排成一排的N个点,要求然你找到一条长度为K的链,起点终点不限,使得其路径总和最小。要求一个点不能走多次。另外假设点i已经走过了,那么我们不能从比i编号大的点走到比i编号小的点,同理也不能从比i编号小的点走到比i编号大的点。思路:枚举每一个起点,每次搜索的时候选择合法区间,记忆化即可。#include<bits/stdc++.h>...原创 2020-04-29 21:48:26 · 316 阅读 · 0 评论 -
Educational Codeforces Round 59 (Rated for Div. 2)(区间DP)(**)
题目链接题意:给一串01串,对该串进行若干次操作,直到串为空,操作为:选择一段连续的0或者1,删除它,拼接前后两部分成为新串,得到价值为a[删除的长度](a为给定的数组)思路:这题貌似是原题?不过我是想不到这么转移的,只能靠大佬的题解勉强理解个大概,以后再来回顾一下。#include<bits/stdc++.h>using namespace std;const int m...原创 2020-04-29 21:45:53 · 210 阅读 · 0 评论 -
hdu5900 QSC and Master (区间DP)
题目链接Problem DescriptionEvery school has some legends, Northeastern University is the same.Enter from the north gate of Northeastern University,You are facing the main building of Northeastern Unive...原创 2020-04-28 22:01:05 · 168 阅读 · 0 评论 -
牛客每日一题 合并回文子串(区间DP)
题目链接题目描述????????????????接到了一份来自校方的委托,虽然没有学分但也必须完成。需要粉刷????条木板,这些木板按照左端对齐,每条木板的高度都是1,第????条木板的长度为????????。????????????????只有一个宽度为1的刷子,她每次可以水平或者竖直地对连续的位置进行粉刷,刷子不能经过没有木板的位置。????????????????对校方的这个安排非常不满,但为了效率,她允许重复粉刷一个位置,希望通过最少的次数来完成这????条木板的粉刷。输...原创 2020-04-28 21:50:12 · 307 阅读 · 0 评论 -
Educational Codeforces Round 1 E. Chocolate Bar(区间DP+记忆化)
题目链接题意:给你n*m的巧克力,然后你想吃面积恰好为k的巧克力,问你怎么样才能花费最少吃到他,每次花费是你切的这刀的长度的平方思路:dp【i】【j】【k】代表i行j列吃恰好为k的最小花费。#include<bits/stdc++.h>using namespace std;typedef long long ll;const int maxn=55;const int...原创 2020-04-27 22:07:04 · 241 阅读 · 1 评论 -
Codeforces Round #336 (Div. 1) B. Zuma(区间DP&&记忆化)
题目链接题意:你可以删除一个回文序列,问你最少操作几次能删完。思路:这里提供两个思路,一个是常见的枚举区间,第二个是记忆化,dp【l】【r】代表区间【l,r】删完的最少次数。枚举区间:#include<bits/stdc++.h>using namespace std;typedef long long ll;int n,dp[501][501],a[501];int...原创 2020-04-26 20:43:58 · 247 阅读 · 0 评论 -
Codeforces Round #106 (Div. 2) D. Coloring Brackets(计数区间DP+记忆化)
题目链接题意:给定一个保证括号匹配的序列,现需要给它染色。要求一、相邻的括号颜色不同 二、匹配的括号必须只有一个染色 三、每个括号有三种选择无色、蓝色、红色。问有多少种染色方案。思路:dp【i】【j】【c1】【c2】代表区间【i,j】,i染成c1,j染成c2的方案数,由于没怎么做过用记忆化的DP,算是见识了以下,由小区间回溯得到大区间的答案。dfs的过程中如果l和r刚好是一对匹配的括...原创 2020-04-26 20:32:49 · 258 阅读 · 0 评论 -
POJ2955 Brackets(区间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 regular b...原创 2020-04-21 21:46:16 · 170 阅读 · 0 评论 -
Codeforces Round #427 (Div. 2) D. Palindromic characteristics(区间DP)
题目链接题意:给出一个字符串,在其中找到1…k阶的回文子串并统计它们的数量。如果一个字符串是一个回文串,则它可以是1阶子串(k阶字符串,要求它的左边和右边都是k-1阶子串)思路:一开始没懂什么是k阶子串,但按照它的定义转移就行了,对于区间【l+1,r-1】是回文的话毫无疑问【l,r】也是,至于【l,r】是几阶回文,取决于左半部分也就是【l,l+len/2-1】,ans记录个数就行了。#in...原创 2020-04-21 21:43:10 · 191 阅读 · 0 评论 -
HDU4283 You Are the One4(区间DP 难)(*)
题目链接Problem Description The 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 ...原创 2020-04-21 21:32:10 · 145 阅读 · 0 评论 -
HDU5115 Dire Wolf(区间DP)
题目链接Problem DescriptionDire wolves, also known as Dark wolves, are extraordinarily large and powerful wolves. Many, if not all, Dire Wolves appear to originate from Draenor.Dire wolves look like no...原创 2020-04-21 21:30:39 · 157 阅读 · 0 评论 -
HDU2476 String painter (区间DP 较难)(*)
题目链接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 ...原创 2020-04-21 21:28:20 · 152 阅读 · 0 评论 -
HDU4745 Two Rabbits(区间DP)
题目链接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 t...原创 2020-04-21 21:25:19 · 231 阅读 · 0 评论 -
HDU4632 Palindrome subsequence(区间DP)
题目链接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 examp...原创 2020-04-21 21:08:31 · 127 阅读 · 0 评论 -
HDU3506 Monkey Party(区间DP+四边不等式优化)(*)
题目链接Problem DescriptionFar 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...原创 2020-04-21 21:06:57 · 140 阅读 · 0 评论 -
Educational Codeforces Round 61 (Rated for Div. 2) F. Clear the String(区间DP)(*)
题目链接思路:区间dp,设f[l][r]是消除l…r区间所花的最小次数#include<bits/stdc++.h>using namespace std;typedef long long ll;const int maxn=505;int n,dp[maxn][maxn];char s[maxn];int main(){ scanf("%d",&n);...原创 2020-04-15 19:55:08 · 133 阅读 · 0 评论 -
Educational Codeforces Round 83 (Rated for Div. 2) E. Array Shrinking(区间DP)
题目链接题意:相同的两个x可以合并成x+1,给一个序列,问最后最少能剩下多少个元素。思路:标准的区间DP,dp【i】【j】代表区间【i,j】内的合并后的最少元素个数。#include <bits/stdc++.h>using namespace std;const int maxn=1005;typedef long long ll;int n,a[maxn][maxn...原创 2020-04-08 21:31:06 · 154 阅读 · 0 评论 -
Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) D. Recovering BST(区间DP)
题目链接思路:还是太菜了,压根想不到可以用区间DP做,设L【i】【k】,R【k】【j】分别表示以k为中心,向左延展至i和向右延展至j。当L【l】【k】&&R【k】【r】的时候通过判断v【k】【r+1】和v【k】【l-1】来看看能否向右和向左延展,v【i】【j】可以预处理,代表的是i到j这段长度的区间gcd是否为1。#include<bits/stdc++.h>...原创 2020-03-12 20:59:09 · 157 阅读 · 0 评论 -
POJ - 1651 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 t...原创 2020-04-14 22:01:45 · 124 阅读 · 0 评论