
动态规划
文章平均质量分 88
m0_51864047
这个作者很懒,什么都没留下…
展开
-
POJ2279 Mr. Young‘s Picture Permutations(线性dp)
DescriptionMr. Young wishes to take a picture of his class. The students will stand in rows with each row no longer than the row behind it and the left ends of the rows aligned. For instance, 12 students could be arranged in rows (from back to front) of 5原创 2021-07-30 12:03:12 · 192 阅读 · 0 评论 -
杭电ACM-LCY算法进阶培训班-专题训练(区间dp)
杭电ACM-LCY算法进阶培训班-专题训练(区间dp) 杭电ACM-LCY算法进阶培训班-专题训练(区间dp)Two RabbitsDire WolfString painterYou Are the OneTwo RabbitsProblem DescriptionLong long ago, there lived two rabbits Tom and Jerry in the forest. On a sunny afternoon, they planned to play a game原创 2021-05-13 16:25:24 · 342 阅读 · 0 评论 -
互不侵犯(状态压缩dp)
题目描述链接在 N×NN×NN×N 的棋盘里面放 KKK 个国王,使他们互不攻击,共有多少种摆放方案。国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共 888 个格子。输入格式只有一行,包含两个数 N,KN,KN,K。输出格式所得的方案数。Input3 2Output16数据范围与提示1≤N≤9,0≤K≤N×N1≤N≤9,0≤K≤N×N1≤N≤9,0≤K≤N×N思路f[i][j][k]f[i][j][k]f[i][j][k] 表示在棋盘的前 iii原创 2021-09-19 21:29:34 · 200 阅读 · 0 评论 -
选课(树上背包)
题目描述链接学校实行学分制。每门的必修课都有固定的学分,同时还必须获得相应的选修课程学分。学校开设了 NNN 门的选修课程,每个学生可选课程的数量 MMM 是给定的。学生选修了这 MMM 门课并考核通过就能获得相应的学分。在选修课程中,有些课程可以直接选修,有些课程需要一定的基础知识,必须在选了其他的一些课程的基础上才能选修。例如《Windows程序设计》必须在选修了《Windows操作基础》之后才能选修。我们称《Windows操作基础》是《Windows程序设计》的先修课。每门课的直接先原创 2021-09-18 15:55:42 · 213 阅读 · 0 评论 -
骑士(树形dp,环套树)
题目描述链接Z 国的骑士团是一个很有势力的组织,帮会中聚集了来自各地的精英。他们劫富济贫,惩恶扬善,受到了社会各界的赞扬。可是,最近发生了一件很可怕的事情:邪恶的 Y 国发起了一场针对 Z 国的侵略战争。战火绵延五百里,在和平环境中安逸了数百年的 Z 国又怎能抵挡得住 Y 国的军队。于是人们把所有希望都寄托在了骑士团身上,就像期待有一个真龙天子的降生,带领正义打败邪恶。骑士团是肯定具备打败邪恶势力的能力的,但是骑士们互相之间往往有一些矛盾。每个骑士有且仅有一个他自己最厌恶的骑士(当然不是他自己),他原创 2021-09-12 18:17:09 · 173 阅读 · 0 评论 -
动态规划匹配正则表达式
leetcode 题目链接cf 题目链接题目描述给你一个字符串 sss 和一个字符规律 ppp,请你来实现一个支持 ‘.’ 和 ‘*’ 的正则表达式匹配。‘.’ 匹配任意单个字符‘*’ 匹配零个或多个前面的那一个元素所谓匹配,是要涵盖整个字符串 sss 的,而不是部分字符串。示例 1:输入:aa a输出:false示例 2:aa a*输出:true示例 3:输入:ab .*输出:true示例 4:aab c*a*b输出:true示例 5:原创 2021-08-23 21:12:46 · 152 阅读 · 0 评论 -
codeforces559C Gerald and Giant Chess(计数dp)
Gerald and Giant ChessGiant chess is quite common in Geraldion. We will not delve into the rules of the game, we’ll just say that the game takes place on an h × w field, and it is painted in two colors, but not like in chess. Almost all cells of the field原创 2021-05-24 21:53:51 · 160 阅读 · 0 评论 -
P1004 [NOIP2000 提高组] 方格取数
题目描述设有 N×NN \times NN×N 的方格图 (N≤9)(N \le 9)(N≤9),我们将其中的某些方格中填入正整数,而其他的方格中则放入数字 000。如下图所示(见样例):某人从图的左上角的 AAA 点出发,可以向下行走,也可以向右走,直到到达右下角的 BBB点。在走过的路上,他可以取走方格中的数(取走后的方格中将变为数字 000)。此人从 AAA 点到 BBB 点共走两次,试找出 222 条这样的路径,使得取得的数之和为最大。输入格式输入的第一行为一个整数 NNN(表示 N×N原创 2021-06-14 14:33:28 · 92 阅读 · 0 评论 -
The Sports Festival(区间dp)
链接The student council is preparing for the relay race at the sports festival.The council consists of nnn members. They will run one after the other in the race, the speed of member iii is sis_isi. The discrepancy did_idi of the iii-th stage is the diff原创 2021-08-23 23:26:22 · 190 阅读 · 0 评论 -
金字塔(区间dp)
题目描述链接虽然探索金字塔是极其老套的剧情,但是有一队探险家还是到了某金字塔脚下。经过多年的研究,科学家对这座金字塔的内部结构已经有所了解。首先,金字塔由若干房间组成,房间之间连有通道。如果把房间看作节点,通道看作边的话,整个金字塔呈现一个有根树结构,节点的子树之间有序,金字塔有唯一的一个入口通向树根。并且,每个房间的墙壁都涂有若干种颜色的一种。探险队员打算进一步了解金字塔的结构,为此,他们使用了一种特殊设计的机器人。这种机器人会从入口进入金字塔,之后对金字塔进行深度优先遍历。机器人每进入原创 2021-09-15 20:46:37 · 232 阅读 · 0 评论 -
Journey(线性dp、并查集)
There are n+1n+1n+1 cities, numbered from 000 to nnn. nnn roads connect these cities, the i-th road connects cities i−1i−1i−1 and i(i∈[1,n])i (i∈[1,n])i(i∈[1,n]).Each road has a direction. The directions are given by a string of nnn characters such that e原创 2021-08-08 16:00:57 · 158 阅读 · 0 评论 -
算法实验 最优二叉搜索树
dp[l][r]=minl<=k<=r(dp[l][k]+dp[k+1][r]+cost[k])dp[l][r]=min_{l<=k<=r}(dp[l][k]+dp[k+1][r]+cost[k])dp[l][r]=minl<=k<=r(dp[l][k]+dp[k+1][r]+cost[k])因为p[1][i−1]+p[i+1][n]+p[i][i]=p[1][n]p[1][i-1]+p[i+1][n]+p[i][i]=p[1][n]p[1][i−1]+p[i+1][原创 2021-04-18 22:24:08 · 1482 阅读 · 1 评论 -
LCIS(线性dp)
链接题目描述熊大妈的奶牛在小沐沐的熏陶下开始研究信息题目。小沐沐先让奶牛研究了最长上升子序列,再让他们研究了最长公共子序列,现在又让他们研究最长公共上升子序列了。小沐沐说,对于两个数列A和B,如果它们都包含一段位置不一定连续的数,且数值是严格递增的,那么称这一段数是两个数列的公共上升子序列,而所有的公共上升子序列中最长的就是最长公共上升子序列了。奶牛半懂不懂,小沐沐要你来告诉奶牛什么是最长公共上升子序列。不过,只要告诉奶牛它的长度就可以了。数列A和B的长度均不超过 300030003000。输入描原创 2021-08-18 17:32:34 · 119 阅读 · 0 评论 -
Array Differentiation(思维、dp)
链接You are given a sequence of nnn integers a1,a2,…,ana_1,a_2,…,a_na1,a2,…,an.Does there exist a sequence of nnn integers b1,b2,…,bnb_1,b_2,…,b_nb1,b2,…,bn such that the following property holds?For each 1≤i≤n1≤i≤n1≤i≤n, there exist two (not necess原创 2021-08-11 23:21:48 · 199 阅读 · 0 评论 -
数字计数(数位dp)
题目描述链接给定两个正整数 aaa 和 bbb,求在 [a,b][a,b][a,b] 中的所有整数中,每个数码 ( digitdigitdigit ) 各出现了多少次。输入格式仅包含一行两个整数 a,ba,ba,b,含义如上所述。输出格式包含一行十个整数,分别表示 0∼90\sim 90∼9 在 [a,b][a,b][a,b] 中出现了多少次。输入1 99输出9 20 20 20 20 20 20 20 20 20数据规模与约定对于 30%30\%30% 的数据,保证 a≤b≤1原创 2021-09-07 22:44:45 · 1535 阅读 · 0 评论 -
算法实验 01背包跳跃点优化
01背包跳跃点优化目录01背包跳跃点优化经典算法的缺点改进的思路(跳跃点)具体方法经典算法的缺点无法处理物品价值、体积为小数的情况当背包容量非常大时,算法的时间复杂度很高改进的思路(跳跃点)通过观察经典算法构建的二维表,发现只有部分“跳跃点”会对结果产生影响,其余点并不能更新最大值。如果只处理这些“跳跃点”,那么就可以克服上面两个缺点。具体方法前i−1i-1i−1个物品所构成的跳跃点(w,v)(w,v)(w,v)是一个递增序列。那么加上第i个物品,相当于每个跳跃点都向右上方移动了一段距原创 2021-04-10 17:46:47 · 1324 阅读 · 0 评论 -
Armchairs(动态规划)
链接There are nnn armchairs, numbered from 111 to nnn from left to right. Some armchairs are occupied by people (at most one person per armchair), others are not. The number of occupied armchairs is not greater than n2\frac n22n.For some reason, you would原创 2021-08-22 15:42:55 · 281 阅读 · 0 评论 -
Double Strings(dp,组合数)
题目描述Given two strings AAA , BBB , and little HHH wants to choose a subsequence from {1,2,⋯ ,∣A∣}\{1, 2, \cdots, |A|\}{1,2,⋯,∣A∣}(call it aaa) and from {1,2,⋯ ,∣B∣}\{1, 2, \cdots, |B|\}{1,2,⋯,∣B∣}(call it bbb) respectively. A scheme is called good iff ∣a∣=原创 2021-08-04 17:20:57 · 390 阅读 · 1 评论 -
Moamen and XOR(dp,位运算,组合数)
链接Moamen and Ezzat are playing a game. They create an array a of nnn non-negative integers where every element is less than 2k2k2k.Moamen wins if a1&a2&a3&…&an≥a1⊕a2⊕a3⊕…⊕ana_1\&a_2\&a_3\&…\&a_n≥a_1⊕a_2⊕a_3⊕…⊕a_na1&a2原创 2021-08-12 17:40:34 · 203 阅读 · 0 评论 -
线性dp与背包dp
01背包完全背包01背包拔河问题多重背包【例题】Coins分组背包NIH Budget线性dp【例题】Armchairs匹配正则表达式小优化状态简化01背包问题描述:给定 NNN 个物品,其中第 iii 个物品的重量为 wiw_iwi,价值为 viv_ivi。有一容积为 MMM 的背包,要求选择一些物品存入背包,使得物品的总重量不超过 MMM 的前提下,物品的价值总和最大。设 dp[i][j]dp[i][j]dp[i][j] 表示,使用前 iii 个物品,当背包重量为 jjj 时,装入价值的最.原创 2021-09-04 18:33:06 · 215 阅读 · 0 评论 -
Kattis - taboo(AC自动机,DAG上DP)
链接Taboo is a popular party game. In this game one player, the Clue Giver, prompts his/her teammates to guess a keyword by giving clues. The Clue Giver is also given a list of taboo strings that must not appear in the clues. For example, if the keyword is原创 2021-10-09 16:57:55 · 179 阅读 · 0 评论