dp
文章平均质量分 86
lyyy.
这里介绍不了我
展开
-
leetcode 300. 最长递增子序列 && 354. 俄罗斯套娃信封问题 && 08.13. 堆箱子
最长递增子序列原题:给你一个整数数组 nums ,找到其中最长严格递增子序列的长度。子序列是由数组派生而来的序列,删除(或不删除)数组中的元素而不改变其余元素的顺序。例如,[3,6,2,7] 是数组 [0,3,1,6,2,2,7] 的子序列。示例 1:输入:nums = [10,9,2,5,3,7,101,18]输出:4解释:最长递增子序列是 [2,3,7,101],因此长度为 4 。示例 2:输入:nums = [0,1,0,3,2,3]输出:4示例 3:输入:num.原创 2021-03-06 01:18:37 · 380 阅读 · 0 评论 -
Codeforces Round #380 B Spotlights -dp
Codeforces Round #380 B Spotlights -dpTheater stage is a rectangular field of size n × m. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.You are to原创 2016-11-20 23:46:55 · 397 阅读 · 0 评论 -
poj2823 Sliding Window 单调队列
Sliding WindowDescriptionAn array of size n ≤ 106 is given to you. There is a sliding window of sizek which is moving from the very left of the array to the very right. You can only see thek n原创 2016-11-14 22:28:43 · 323 阅读 · 0 评论 -
poj 1836 Alignment -dp(合唱队形变式)-最长上升子序列+最长下降子序列
In the army, a platoon is composed by n soldiers. During the morning inspection, the soldiers are aligned in a straight line in front of the captain. The captain is not satisfied with the way his soldiers are aligned; it is true that the soldiers are align原创 2016-10-25 23:38:01 · 580 阅读 · 0 评论 -
poj 1837 Balance -dp-01背包
BalanceGigel has a strange "balance" and he wants to poise it. Actually, the device is different from any other ordinary balance. It orders two arms of negligible weight and each arm's length is 15. Some hooks are attached to these arms and Gigel wants t原创 2016-10-22 16:44:03 · 312 阅读 · 0 评论 -
hdu5904 BestCoder Round #87 LCIS -dp
LCISAlex has two sequences a1,a2,...,an and b1,b2,...,bm. He wants find a longest common subsequence that consists of consecutive values in increasing order.There are multiple test cases. The first line of input contains an integer T, indicating the numb原创 2016-09-24 23:26:09 · 406 阅读 · 0 评论 -
hdu 5900 QSC and Master -ICPC网络赛沈阳赛区-区间dp
QSC and MasterEvery 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 University.Ninety-nine percent of the students have not been there,It i原创 2016-09-20 15:35:44 · 338 阅读 · 0 评论 -
poj1276 Cash Machine-多重背包
A Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bills for a requested cash amount. The machine uses exactly N distinct bill denominations, say Dk, k=1,N, and for each denomination Dk the machine has a sup原创 2016-09-03 09:09:53 · 284 阅读 · 0 评论 -
poj2823 Sliding Window 单调队列
An array of size n ≤ 106 is given to you. There is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves rightwards by one position. Fo原创 2016-09-13 17:34:35 · 440 阅读 · 2 评论 -
hdu1078 FatMouse and Cheese 搜索dfs&dp
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 grid location Fatmouse has hid between 0 and 100 blocks of cheese in a hole原创 2016-09-13 13:54:50 · 317 阅读 · 0 评论 -
状态压缩(棋盘问题+hdu3254+poj1185+hud2553)
在n*n(n≤20)的方格棋盘上放置 n 个车(可以攻击所在行、列),求使它们不能互相攻击的方案总数。状态压缩递推:在n*n(n≤20)的方格棋盘上放置 n 个车,某些格子不能放,求使它们不能互相攻击的方案总数。给出一个 n*m 的棋盘(n 、m≤ 80,n*m ≤ 80),要在棋盘上放 k(k ≤ 20)个棋子, 使得任意两个棋子不相邻。问有多少种方案。hdu - 3254 corn fields poj1185炮兵阵地hdu 2553 n皇后问题nyoj-492 kingpoj2411-原创 2016-08-02 11:05:08 · 2581 阅读 · 0 评论 -
ural 1005. Stone Pile -01背包-dp
1005. Stone PileYou have a number of stones with known weights w1, …, wn. Write a program that will rearrange the stones into two piles such that weight difference between the piles is minimal.Input contains the number of stones n (1 ≤ n ≤ 20) and weights原创 2016-11-23 19:54:27 · 622 阅读 · 0 评论 -
ural 1009. K-based Numbers - dp
1009. K-based NumbersLet’s consider K-based numbers, containing exactly N digits. We define a number to be valid if its K-based notation doesn’t contain two successive zeros. For example: 1010230 is a valid 7-digit number; 1000198 is not a valid number;原创 2016-11-24 23:57:10 · 445 阅读 · 0 评论 -
hdu 2084 数塔 - dp
有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少?原创 2017-03-08 13:15:53 · 255 阅读 · 0 评论 -
PAT甲级练习题-Maximum Subsequence Sum (25)-最大子序列和
1007. Maximum Subsequence Sum (25)时间限制 400 ms内存限制 65536 kB代码长度限制 16000 B判题程序 Standard 作者 CHEN, YueGiven a sequence of K integers { N1, N2, ...,原创 2018-04-18 14:35:43 · 303 阅读 · 0 评论 -
L3-001. 凑零钱-dp-满01背包
L3-001. 凑零钱时间限制 200 ms内存限制 65536 kB代码长度限制 8000 B判题程序 Standard 作者 陈越韩梅梅喜欢满宇宙到处逛街。现在她逛到了一家火星店里,发现这家店有个特别的规矩:你可以用任何星球的硬币付钱,但是绝不找零,当然也不能欠债。韩梅梅手边有104原创 2018-03-20 16:31:54 · 321 阅读 · 1 评论 -
最长回文子串Manacher O(n)解法+ 区间dp O(n2)解法
题解转自博客:www.cnblogs.com/mickole/articles/3578298.html题目:(替代题目可去pat天梯赛练习题中寻找,当然那个题n3也能过)长度为N(N很大)的字符串,求这个字符串里的最长回文子串?(百度2014校招笔试题目)题目指出“N很大”,就是提示我们不要想通过遍历的方法来找到这个字符串,我想到的就一种解法,时间复杂度应该不高,但是我算原创 2018-02-05 14:03:19 · 804 阅读 · 0 评论 -
M. Frequent Subsets Problem - 状态压缩-2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
M. Frequent Subsets Problem - 状态压缩-2017 ACM-ICPC 亚洲区(南宁赛区)网络赛The frequent subset problem is defined as follows. Suppose UUU={1, 2,…\ldots…,N} is the universe, and S1S_{1}S1,S2S_{2}S2,…\ldots…,SMS_{M}SM are MMM sets over UUU. Given a positive const原创 2017-09-24 16:43:49 · 359 阅读 · 0 评论 -
L. The Heaviest Non-decreasing Subsequence Problem -最长不降子序列变形nlogn-2017 ACM-ICPC 亚洲区(南宁赛区)网络赛
L. The Heaviest Non-decreasing Subsequence Problem -最长不降子序列变形nlogn-2017 ACM-ICPC 亚洲区(南宁赛区)网络赛Let SSS be a sequence of integers s1s_{1}s1,s2s_{2}s2,.........,sns_{n}sn Each integer is is associated with a weight by the following rules1) If is is ne原创 2017-09-24 16:42:54 · 386 阅读 · 0 评论 -
HDU6103 Kirinriki-dp+二分 - 2017多校联盟6 第8题
HDU6103 Kirinriki-dp+二分 - 2017多校联盟6 第8题We define the distance of two strings A and B with same length n isdisA,B=∑i=n−1|Ai−Bn−1−i|The difference between the two characters is defined as thedifference in ASCII.You should find the maximum length of two non-o原创 2017-08-11 18:02:36 · 374 阅读 · 0 评论 -
HDU6092 Rikka with Subset-01背包dp-2017多校联盟5 第8题
HDU6092 Rikka with Subset-01背包dp-2017多校联盟5 第8题As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:Yuta has npositive A1−Anand their sum is m. Then for each subset Sof原创 2017-08-09 19:10:19 · 310 阅读 · 1 评论 -
浙江省赛E zoj 3962 Seven Segment Display
Seven Segment DisplayTime Limit: 2 Seconds Memory Limit: 65536 KB A seven segment display, or seven segment indicator, is a form of electronic display device for displaying decimal nume原创 2017-04-25 12:07:29 · 421 阅读 · 0 评论 -
划分数-dp-挑战程序设计竞赛
挑战程序设计竞赛上有这么一道题:有n个无区别的物品,将它们划分为不超过m组,求出划分方法数模M的余数。原创 2017-03-30 20:09:11 · 512 阅读 · 0 评论 -
hdu 2089 不要62 - 数位dp
杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer)。杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍,更安全地服务大众。不吉利的数字为所有含有4或62的号码。例如:62315 73418 88914都属于不吉利号码。但是,61152虽然含有6和2,但不是62连号,所以不属于不吉利数字之列。你的任务是,对于每次给出的一个牌照区间号,推断出交管局今次又要实际上给多少辆新的士车上牌照了。原创 2017-03-08 17:30:30 · 202 阅读 · 0 评论 -
poj1661 Help Jimmy-dp动态规划
场景中包括多个长度和高度各不相同的平台。地面是最低的平台,高度为零,长度无限。 Jimmy老鼠在时刻0从高于所有平台的某处开始下落,它的下落速度始终为1米/秒。当Jimmy落到某个平台上时,游戏者选择让它向左还是向右跑,它跑动的速度也是1米/秒。当Jimmy跑到平台的边缘时,开始继续下落。Jimmy每次下落的高度不能超过MAX米,不然就会摔死,游戏也会结束。 设计一个程序,计算Jimmy到底地面时可能的最早时间。原创 2016-08-31 14:26:02 · 1531 阅读 · 3 评论 -
状态压缩-覆盖问题-poj 2411 2663
poj2411-Mondriaan's Dream题目大意 用1*2的骨牌覆盖n*m的棋盘,问有多少种方案。可以旋转90°放。不能覆盖则输出0。解题思路用 f【i,s】表示 把前 i-1 行覆盖满、第 i 行覆盖状态为 s 的覆盖方案数。因为在第 i 行上放置的骨牌多也只能影响到第 i-1 行(竖着放的时候是占用当前行和上一行),因此要满足在填第i行时,第1~i-2原创 2016-08-09 10:01:30 · 680 阅读 · 0 评论 -
ural1057Amount of Degrees-数位dp
题目地址:http://acm.timus.ru/problem.aspx?space=1&num=10571057. Amount of DegreesTime limit: 1.0 secondMemory limit: 64 MBCreate a code to determine the amount of integers, lying in the set [X原创 2016-08-08 15:43:19 · 583 阅读 · 0 评论 -
删数-dp区间型动态规划
题目描述有N个不同的正整数数x1, x2, ... xN 排成一排,我们可以从左边或右边去掉连续的i个数(只能从两边删除数),1输入第一行为一个正整数N,第二行有N个用空格隔开的N个不同的正整数。 3<=N<=100,N个操作数为1..1000 之间的整数。输出输出文件remove.out 包含一个正整数,为操原创 2016-07-26 14:57:02 · 1337 阅读 · 0 评论 -
沙子合并-dp
题目地址:http://acm.qust.edu.cn/problem.php?cid=1168&pid=0问题 A: 沙子合并时间限制: 1 Sec 内存限制: 128 MB 题目描述设有N堆沙子排成一排,其编号为1,2,3,…,N(N<=300)。每堆沙子有一定的数量,可以用一个整数来描述,现在要将这N堆沙子合并成为一堆,每次只能合并相邻的两堆,合并的代价为这两堆沙原创 2016-07-25 20:43:45 · 2707 阅读 · 1 评论 -
NOIP2006能量项链-dp
题目地址:http://acm.qust.edu.cn/problem.php?cid=1168&pid=1能量项链时间限制: 1 Sec 内存限制: 128 MB 题目描述在Mars星球上,每个Mars人都随身佩带着一串能量项链。在项链上有N颗能量珠。能量珠是一颗有头标记与尾标记的珠子,这些标记对应着某个正整数。并且,对于相邻的两颗珠子,前一颗珠子的尾标记一原创 2016-07-25 20:36:51 · 668 阅读 · 1 评论 -
noip1995石子合并-dp
题目地址:https://www.rqnoj.cn/problem/490在一个圆形操场的四周摆放n堆石子(n≤500),现要将石子有次序地合并成一堆。规定每次只能选相邻的两堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分。编一程序,由文件读入堆数n及每堆的石子数;⑴选择一种合并石子的方案,使得做n-1次合并,得分的总和最小;⑵选择一种合并石子的方案,使得做...原创 2016-07-25 15:02:51 · 2364 阅读 · 5 评论 -
hdu4826Labyrinth-dp动态规划
Problem Description度度熊是一只喜欢探险的熊,一次偶然落进了一个m*n矩阵的迷宫,该迷宫只能从矩阵左上角第一个方格开始走,只有走到右上角的第一个格子才算走出迷宫,每一次只能走一格,且只能向上向下向右走以前没有走过的格子,每一个格子中都有一些金币(或正或负,有可能遇到强盗拦路抢劫,度度熊身上金币可以为负,需要给强盗写欠条),度度熊刚开始时身上金币数为0,问度度熊走出迷宫时候身上原创 2016-07-24 23:01:00 · 724 阅读 · 1 评论 -
机器分配-分组背包&&线性动态规划
题目描述某总公司拥有高效生产设备M台,准备分给下属的N个分公司。各分公司若获得这些设备,可以为总公司提供一定的盈利。问:如何分配这M台设备才能使国家得到的盈利最大?求出最大盈利值。 分配原则:每个公司有权获得任意数目的设备,但总台数不得超过总设备数M。其中M<=100,N<=100。输入第一行为两个整数M,N。接下来是一个N×M的矩阵,其中矩阵的第i行的第j列的数Aij表明第i个公原创 2016-07-23 19:07:27 · 1396 阅读 · 0 评论 -
尼克的任务-线性dp
题目地址:http://acm.qust.edu.cn/problem.php?id=1783尼克的任务 题目描述尼克每天上班之前都连接上英特网,接收他的上司发来的邮件,这些邮件包含了尼克主管的部门当天要完成的全部任务,每个任务由一个开始时刻与一个持续时间构成。 尼克的一个工作日为N分钟,从第一分钟开始到第N分钟结束。当尼克到达单位后他就开始干活。如果在同一时刻有多个任务需原创 2016-07-23 20:04:48 · 948 阅读 · 0 评论 -
奶牛的锻炼-线性dp
题目地址:http://acm.qust.edu.cn/problem.php?id=1782题目描述奶牛Bessie有N分钟时间跑步,每分钟她可以跑步或者休息。若她在第i分钟跑步,可以跑出D_i米,同时疲倦程度增加1(初始为0)。若她在第i分钟休息,则疲倦程度减少1。无论何时,疲倦程度都不能超过M。另外,一旦她开始休息,只有当疲惫程度减为0时才能重新开始跑步。在第N分钟后,她的疲倦程原创 2016-07-23 17:12:03 · 467 阅读 · 0 评论 -
最长公共子序列-dp
题目描述:一个给定序列的子序列是在该序列中删去若干元素后得到的序列。确切地说,若给定序列X=>,若另一序列Z=>是X的子序列,是指存在一个严格递增的下标序列>,使得对于所有j=1,2,…,k有例如,序列Z=是序列X=的子序列,相应的递增下标序列为。给定两个序列X和Y,当另一序列Z既是X的子序列又是Y的子序列时,称Z是序列X和Y的公共子序列。例如,若X=和Y=,则序列是X和Y的一个公共子序列原创 2016-07-22 19:27:30 · 1184 阅读 · 0 评论 -
noip 2004-合唱队形-dp
题目地址:https://vijos.org/p/1098描述N位同学站成一排,音乐老师要请其中的(N-K)位同学出列,使得剩下的K位同学排成合唱队形。合唱队形是指这样的一种队形:设K位同学从左到右依次编号为1,2…,K,他们的身高分别为T1,T2,…,TK, 则他们的身高满足T1Ti+1>…>TK(1你的任务是,已知所有N位同学的身高,计算最少需要几位同学出列,可以使得剩原创 2016-07-22 16:03:01 · 1104 阅读 · 0 评论 -
NOIP2003-加分二叉树-dp-区间型动态规划
题目地址:https://vijos.org/p/1100描述设一个n个节点的二叉树tree的中序遍历为(l,2,3,…,n),其中数字1,2,3,…,n为节点编号。每个节点都有一个分数(均为正整数),记第i个节点的分数为di,tree及它的每个子树都有一个加分,任一棵子树subtree(也包含tree本身)的加分计算方法如下:subtree的左子树的加分× subtree的右原创 2016-07-26 18:23:12 · 541 阅读 · 0 评论 -
精卫填海-动态规划dp-01背包
地址:https://vijos.org/p/1625描述【版权说明】本题为改编题。【问题描述】发鸠之山,其上多柘木。有鸟焉,其状如乌,文首,白喙,赤足,名曰精卫,其名自詨。是炎帝之少女,名曰女娃。女娃游于东海,溺而不返,故为精卫。常衔西山之木石,以堙于东海。——《山海经》精卫终于快把东海填平了!只剩下了最后的一小片区域了。同时,西山上的木石也已经不多了。精卫能把东海填原创 2016-07-27 11:46:43 · 401 阅读 · 0 评论 -
GF-动态规划dp-多维费用的背包
题目地址:https://vijos.org/p/1544题目描述"找啊找啊找GF,找到一个好GF,吃顿饭啊拉拉手,你是我的好GF.再见.""诶,别再见啊..."七夕...七夕...七夕这个日子,对于sqybi这种单身的菜鸟来说是多么的痛苦...虽然他听着这首叫做"找啊找啊找GF"的歌,他还是很痛苦.为了避免这种痛苦,sqybi决定要给自己找点事情干.他去找到了七夕模拟赛的负责原创 2016-07-27 13:06:17 · 2068 阅读 · 0 评论