dp动态规划题
m悟空
这个作者很懒,什么都没留下…
展开
-
整数划分 (dp)
将N分为若干个不同整数的和,有多少种不同的划分方式,例如:n = 6,{6} {1,5} {2,4} {1,2,3},共4种。由于数据较大,输出Mod 10^9 + 7的结果即可。Input输入1个数N(1 <= N <= 50000)。Output输出划分的数量Mod 10^9 + 7。Sample Input6Sample Output4题意:对...原创 2018-09-02 21:25:28 · 384 阅读 · 0 评论 -
悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 (背包问题 dp)
急!灾区的食物依然短缺! 为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都是袋装产品,其价格不等,并且只能整袋购买。 请问:你用有限的资金最多能采购多少公斤粮食呢? 后记: 人生是一个充满了变数的生命过程,天灾、人祸、病痛是我们生命历程中不可预知的威胁。 月有阴晴圆缺,人有旦夕祸福,未来对于我们而言是一个未知数。...原创 2018-07-29 13:29:22 · 224 阅读 · 0 评论 -
Maximum Sum (最大的子矩阵的和)
A problem that is simple to solve in one dimension is often much more difficult to solve in more than one dimension. Consider satisfying a boolean expression in conjunctive normal form in which each c...原创 2018-07-22 15:17:27 · 587 阅读 · 0 评论 -
Filthy Rich (dp)
They say that in Phrygia, the streets are paved with gold. You’re currently on vacation in Phrygia, and to your astonishment you discover that this is to be taken literally: small heaps of gold are di...原创 2018-07-18 20:22:27 · 199 阅读 · 0 评论 -
数字0-9的数量 (数位dp ,技巧)
给出一段区间a-b,统计这个区间内0-9出现的次数。比如 10-19,1出现11次(10,11,12,13,14,15,16,17,18,19,其中11包括2个1),其余数字各出现1次。 收起输入两个数a,b(1 <= a <= b <= 10^18)输出输出共10行,分别是0-9出现的次数输入样例10 19输出样例11111...原创 2019-02-16 15:46:48 · 1335 阅读 · 0 评论 -
回文字符串(最少添加多少个字符才能构成回文串,最长公共子序列)
回文串是指aba、abba、cccbccc、aaaa这种左右对称的字符串。每个字符串都可以通过向中间添加一些字符,使之变为回文字符串。例如:abbc 添加2个字符可以变为 acbbca,也可以添加3个变为 abbcbba。方案1只需要添加2个字符,是所有方案中添加字符数量最少的。 收起输入输入一个字符串Str,Str的长度 <= 1000。输出输出最少添加多少个字...原创 2019-02-17 02:16:55 · 4000 阅读 · 0 评论 -
不要62 (数位dp)
杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer)。杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍,更安全地服务大众。不吉利的数字为所有含有4或62的号码。例如:62315 73418 88914都属于不吉利号码。但是,61152虽然含有6和2,但不是62连号,所以不属于不吉利数字之...原创 2019-04-04 21:23:44 · 142 阅读 · 0 评论 -
Dire Wolf (区间dp经典题)
Dire 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 normal wolves, but these ...原创 2019-04-11 09:17:58 · 1658 阅读 · 0 评论 -
Max answer (求区间最小值乘区间和的最大结果,维护左右区间+st求区间最大,最小值)
Alice has a magic array. She suggests that the value of a interval is equal to the sum of the values in the interval, multiplied by the smallest value in the interval.Now she is planning to find the...原创 2019-04-21 15:09:09 · 3023 阅读 · 0 评论 -
最大下降矩阵(行的 最长上升子序列)
题目描述我们称一个矩阵是下降矩阵,当且仅当,矩阵的每一列都是严格下降的。很显然,这个要求很苛刻,大多数矩阵都无法满足。但是显然如果消去一些行,一定可以使得这个矩阵变成下降矩阵。现在给出一个n行m列的矩阵,请你求出最少消去多少行,可以使得这个矩阵变为下降矩阵。输入输入第一行包含两个正整数n,m分别表示矩阵的行数和列数。(1<=n,m<=300)接下来n行,每行有m个数,中...原创 2019-04-17 11:22:05 · 426 阅读 · 0 评论 -
Rikka with Coin(10,20,50,100组成给定任意数的最少使用量)
Rikka hates coins, and she used to never carry any coins with her. These days, Rikka is doing her summer internship abroad. Without mobile payment, Rikka has to face strange prices of commodities, and...原创 2019-08-20 20:25:55 · 244 阅读 · 0 评论 -
棋盘分割 (矩阵分割求最小方差 dp)
将一个8*8的棋盘进行如下分割:将原棋盘割下一块矩形棋盘并使剩下部分也是矩形,再将剩下的部分继续如此分割,这样割了(n-1)次后,连同最后剩下的矩形棋盘共有n块矩形棋盘。(每次切割都只能沿着棋盘格子的边进行) 原棋盘上每一格有一个分值,一块矩形棋盘的总分为其所含各格分值之和。现在需要把棋盘按上述规则分割成n块矩形棋盘,并使各矩形棋盘总分的均方差最小。 均方差 ,其中平均值 ,x i为第...原创 2018-07-29 15:33:41 · 1153 阅读 · 0 评论 -
Palindrome (再加多少个字符才能成为回文串 dp)
A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determines the minimal numb...原创 2018-08-02 16:50:15 · 367 阅读 · 0 评论 -
Bridging signals (排序 + 最长上升子序列)
Oh no, they've done it again', cries the chief designer at the Waferland chip factory. Once more the routing designers have screwed up completely, making the signals on the chip connecting the ports o...原创 2018-08-02 17:24:58 · 264 阅读 · 0 评论 -
Super Jumping! Jumping! Jumping! (上升子序列的最大和)
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 game ...原创 2018-08-26 21:25:51 · 2029 阅读 · 1 评论 -
Anniversary party (树上dp + dfs)
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 forms a tr...原创 2018-08-26 16:55:46 · 127 阅读 · 0 评论 -
Functions again (最大子序列和)
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arr...原创 2018-08-19 21:57:36 · 571 阅读 · 4 评论 -
数组的最大代价 (dp)
数组A包含N个元素A1, A2......AN。数组B包含N个元素B1, B2......BN。并且数组A中的每一个元素Ai,都满足1 <= Ai <= Bi。数组A的代价定义如下: (公式表示所有两个相邻元素的差的绝对值之和)给出数组B,计算可能的最大代价S。Input第1行:1个数N,表示数组的长度(1 <= N <= 50000)。 第...原创 2018-08-09 17:23:46 · 259 阅读 · 0 评论 -
Cheapest Palindrome(dp 构成回文串的最小花费)
Keeping track of all the cows can be a tricky task so Farmer John has installed a system to automate it. He has installed on each cow an electronic ID tag that the system will read as the cows pass by...原创 2018-08-05 14:13:20 · 404 阅读 · 0 评论 -
FatMouse's Speed (最长上升子序列 + 路径输出)
FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence...原创 2018-08-05 14:03:10 · 652 阅读 · 0 评论 -
Greatest Common Increasing Subsequence (最长公共上升子序列的长度)
This is a problem from ZOJ 2432.To make it easyer,you just need output the length of the subsequence.InputEach sequence is described with M - its length (1 <= M <= 500) and M integer numbers...原创 2018-08-05 13:45:56 · 376 阅读 · 0 评论 -
Largest Rectangle in a Histogram (连续矩形 够成矩形的最大面积 dp)
A histogram is a polygon composed of a sequence of rectangles aligned at a common base line. The rectangles have equal widths but may have different heights. For example, the figure on the left shows ...原创 2018-08-05 13:29:10 · 376 阅读 · 0 评论 -
搬寝室 (dp)
搬寝室是很累的,xhd深有体会.时间追述2006年7月9号,那天xhd迫于无奈要从27号楼搬到3号楼,因为10号要封楼了.看着寝室里的n件物品,xhd开始发呆,因为n是一个小于2000的整数,实在是太多了,于是xhd决定随便搬2*k件过去就行了.但还是会很累,因为2*k也不小是一个不大于n的整数.幸运的是xhd根据多年的搬东西的经验发现每搬一次的疲劳度是和左右手的物品的重量差的平方成正比(这里补充...原创 2018-08-05 13:20:09 · 623 阅读 · 0 评论 -
饭卡 (dp)
电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够)。所以大家都希望尽量使卡上的余额最少。 某天,食堂中有n种菜出售,每种菜可购买一次。已知每种菜的价格以及卡上的余额,问最少可使卡上的余额为多少。 Input多组数据。对于每组数据: 第一行为正整数n...原创 2018-08-05 13:09:20 · 1472 阅读 · 0 评论 -
Hello 2019 (线段树维护矩阵实现任意区间的dp)
A digital string is "good": when it contains a subsequence91029102and does not contain a subsequence81028102.The bad value of a string is defined as how many characters are to remove at least, so...原创 2019-09-14 09:37:58 · 425 阅读 · 0 评论