dp
文章平均质量分 69
黑码
这个作者很懒,什么都没留下…
展开
-
codeforces Nastya and Scoreboard(dp)
题意:0~9每个数字由不同数量位置的火柴棍组成,一共n组数字,让你添加k根火柴棍,使n组数字可以构造的最大的数。若不能构成任何数,那么输出 -1dp[i][j] 第i个数时,还剩下j个火柴棍,dp[i][j] = 1代表这个状态是可以构成的。那么初始值 dp[n+1][0] = 1代表 n+1个数时,剩下0个火柴棍的状态是1。从后往前推可以达到的状态,最后从前往后贪心得到结果。#incl...原创 2020-04-25 10:41:10 · 199 阅读 · 0 评论 -
leetcode1406. 石子游戏 III 零和博弈
Alice 和 Bob 用几堆石子在做游戏。几堆石子排成一行,每堆石子都对应一个得分,由数组 stoneValue 给出。Alice 和 Bob 轮流取石子,Alice 总是先开始。在每个玩家的回合中,该玩家可以拿走剩下石子中的的前 1、2 或 3 堆石子 。比赛一直持续到所有石头都被拿走。每个玩家的最终得分为他所拿到的每堆石子的对应得分之和。每个玩家的初始分数都是 0 。比赛的目标是决出...原创 2020-04-12 18:22:33 · 263 阅读 · 0 评论 -
codeforces 627 div3 E. Sleeping Schedule
E. Sleeping Scheduletime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVova had a pretty weird sleeping schedule. There areℎhhour...原创 2020-03-12 23:21:36 · 662 阅读 · 4 评论 -
2017之江学院校赛 B qwb与矩阵 dp+优化
Problem B: qwb与矩阵 Time Limit: 2 Sec Memory Limit: 128 MB Submit: 935 Solved: 155 [Submit][Status][Web Board] Description 做完了辣么多的数学题,qwb好好睡了一觉。但是他做了一个梦:有一个n*m的矩阵,qwb在这个矩阵的左上角(1,1),终点在右下角(n,m)。每个格原创 2017-06-02 10:00:59 · 385 阅读 · 0 评论 -
之江学院 M qwb与二叉树 卡特兰数+dp
Problem M: qwb与二叉树 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 121 Solved: 24 [Submit][Status][Web Board] Description 某一天,qwb正在上数据结构课。老师在讲台上面讲着二叉树,qwb在下面发着呆。 突然qwb想到一个问题:对于一棵n个无编号节点,m个叶子的有根二转载 2017-06-02 16:50:31 · 696 阅读 · 0 评论 -
uvalive 4764 Bing it 基础dp
I guess most of you played cards on the trip to Harbin, but I’m sure you have never played the following card game. This card game has N rounds and 100000 types of cards numbered from 1 to 100000. A原创 2017-04-28 01:00:12 · 311 阅读 · 0 评论 -
codeforces 494B kmp+dp
Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking原创 2017-04-27 01:04:49 · 418 阅读 · 0 评论 -
背包dp小tips
1.一维的01背包为啥要逆序(保证更新f[j]时,f[ j - weight[i] ]是没有放入物品i时的数据即f[ i - 1 ][ j - weight[i] ],因为01背包每个物品至多被选一次。而完全背包中,每个物品可以被选无限次,那么状态f[i][j],正好可以由可能已经放入物品i的状态f[ i - 1 ][ j - weight[i] ]转移而来。所以,遍历顺序改为顺序时,就是完全背包问原创 2017-01-19 00:23:22 · 369 阅读 · 0 评论 -
hdu 1114 Piggy-Bank (完全背包)
题意:存钱罐可以往里面放一些价值小的钱,但是时间久了就不知道里面有多少钱了,除非你打破它。现在给出空罐子的重量和最满能装到多重,然后给出每种硬币的价值和重量,我们要在不打破它的情况下确认罐子里最少有多少钱。 for i 1~n; for j w[i]~weight; dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]); 由于 http://blog.原创 2017-02-06 12:14:01 · 769 阅读 · 0 评论 -
Multiplication Puzzle (区间dp) poj1651
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 the pro原创 2017-04-02 12:09:55 · 277 阅读 · 0 评论 -
Wooden Signs uvalive gym 区间dp
详细题目见:http://7xjob4.com1.z0.glb.clouddn.com/0f10204481da21e62f8c145939e5828e 思路:记dp[i][j]表示第i个木板尾部在j的方案数。那么对于i+1,可以分三种情况讨论,一种是i+1的头部在第i根整段的左边,一种是在右边,还有在中间,中间的有两种情况,其他都只有一种,然后就可以转移了。 转载 http://blog.cs转载 2017-03-29 10:44:05 · 362 阅读 · 0 评论 -
poj 1141(区间dp 滚动数组)
题意:有M个人,我们任选3个人组成一个队伍,可以组成C(M,3)种队伍,给出这些队伍之间的胜率。现在,需要你战胜N个队伍。战胜该队伍,你可选择用战胜的队伍来替换你现有的队伍。现在要求战胜这N个队伍的最大概率。 思路:因为对于战胜的队伍,我们可以选择替换还是不替换,这就像01背包。因为N非常大,我们需要考虑O(N)的递推方程。 如果我们从前向后递推,会存在一个后效性的问题,原创 2017-04-03 15:41:54 · 520 阅读 · 0 评论 -
树形dp 总结(转)
转自 :http://blog.csdn.net/txl199106/article/details/45373507树状动态规划定义 之所以这样命名树规,是因为树形DP的这一特殊性:没有环,dfs是不会重复,而且具有明显而又严格的层数关系。利用这一特性,我们可以很清晰地根据题目写出一个在树(型结构)上的记忆化搜索的程序。而深搜的特点,就是“不撞南墙不回头”。这一点在之后的文章中会详细的介绍。转载 2017-04-06 00:40:39 · 349 阅读 · 0 评论 -
uvalive 5088 hdu3066(树形dp)
题意:给出一棵n个结点的树,两个人一起走,轮流决策 Alice目的是使最后距离最小 Bob相反 问最终走的距离能否满足区间[L,R] (需要走到最后不能走,所以Alice不能不选就结束了) 如果没有[L,R],直解dfs,Bob的话选最大儿子走,Alice选最小儿子走 现在多了[L,R],选的时候,就需要判断满足总距离(是总距离!!即答案)满原创 2017-04-06 00:39:12 · 397 阅读 · 0 评论 -
codeforces 580D Kefa and Dishes (状压dp)
题意:有n种菜(每一种菜有一个满意值ai>=0),你准备吃m种,每种一次。但是如果你按某种规则吃两种菜的话会增加额外的满意值,比如规则(xi yi ci)就是你先吃第xi个菜,然后马上吃第yi个菜,那么你就会额外增加ci点满意值。有k个这样的规则,问你吃m种菜后的最大满意值是多少。dp[st][i] 代表在 st状态下,种第i棵菜 然后状态转移 如果在st状态下,已经种了j,那么可以选择把ij种一起原创 2017-04-15 11:09:10 · 504 阅读 · 0 评论 -
zoj 3956 01背包
题意:给了n个物品,每个物品有两个值,H和C 问你怎么取, 使最后 (∑i=1mHxi)2−(∑i=1mHxi)×(∑i=1mCxi)−(∑i=1mCxi)2这个东西最大。分析:。。真是 醉了,被数学公式吓倒了,以为是数学题,没想到是dp。。傻瓜01背包。。 我是大傻瓜。。服我自己 01背包变形,公式是h越大 c越小越好。肯定不能单个考虑,因为会相互影响,那么就是dp了。 求,c不变时,h越原创 2017-04-17 20:32:24 · 362 阅读 · 0 评论 -
傻逼服务器 A序列 nlogn dp序列
A序列 发布时间: 2017年7月9日 18:17 最后更新: 2017年7月9日 21:05 时间限制: 1000ms 内存限制: 128M 描述 如果一个序列有奇数个正整数组成,不妨令此序列为a 1 ,a 2 ,a 3 ,…,a 2∗k+1 (0<=k ),并且a 1 ,a 2 …a k+1 是一个严格递增的序列,a k+1 ,a k+2 ,…,a 2∗k+1 ,是一个严原创 2017-07-10 15:12:33 · 430 阅读 · 0 评论 -
poj 3728 merchant 一个比较复杂的lca+dp
There are N cities in a country, and there is one and only one simple path between each pair of cities. A merchant has chosen some paths and wants to earn as much money as possible in each path. When h原创 2017-06-03 13:48:30 · 413 阅读 · 0 评论 -
CodeForces - 988F Rain and Umbrellas (dp)
题目大意:有三个整数a,n,m,a是终点坐标,给出n个范围(l,r)表示这块区域下雨,m把伞(p,w)在点p有重量为w的伞。小明可以携带任意数量的伞,经过下雨处时必须要撑伞,小明每走一个单位长度消耗的体力与他所携带伞的重量相同,求小明从0~a所需消耗的最少体力,若无解则输出-1。 思路:可以考虑 从 1 到 a一步步转移过去的 o(n)做法,但是写起来比较麻烦,需要保存三种状态...原创 2018-12-31 17:16:08 · 231 阅读 · 0 评论 -
最大上升子序列(从前往后) nlogn 和最大上升序列(从后往前)
#includeusing namespace std;const int N = 1e5+10;int arr[N],len1[N],len2[N];int len,ans[N];int tot;int T[N];int ls[N*20],rs[N*20],sum[N*20];int binary_search(int i){ int left,right,mid;原创 2017-10-21 01:05:27 · 348 阅读 · 0 评论 -
hdu 5791 Two (dp)
Alice gets two sequences A and B. A easy problem comes. How many pair of sequence A’ and sequence B’ are same. For example, {1,2} and {1,2} are same. {1,2,4} and {1,4,2} are not same. A’ is a subsequen原创 2017-09-02 00:29:54 · 456 阅读 · 0 评论 -
codeforces 864E Fire (排序+背包dp)
题目大意: 现在你有n个物品,每个物品三个属性,我个人记为a,b,c. a表示你需要花a的时间去救这个物品,b表示到b时间后物品就销毁了,c表示救这个物品的价值,求出能救到的最大价值。 n <= 100 b <= 2000 c <= 20 a <= 20 排序后dp,要先救活时间短的,所以就是从小到大排序#include <bits/stdc++.h>using namespace s原创 2017-09-26 16:13:19 · 410 阅读 · 0 评论 -
hihocoder 1580(最大子矩阵变形)
时间限制:1000ms单点时限:1000ms内存限制:256MB描述Once upon a time, there was a little dog YK. One day, he went to an antique shop and was impressed by a beautiful picture. YK loved it very much.原创 2017-09-26 10:31:08 · 542 阅读 · 0 评论 -
Buns CodeForces - 106C 多重背包
Lavrenty, a baker, is going to make several buns with stuffings and sell them.Lavrenty has n grams of dough as well as m different stuffing types. The stuffing types are numerated from 1 to m. Lavrenty原创 2017-08-09 23:48:56 · 362 阅读 · 0 评论 -
codeforces 755F PolandBall and Gifts(多重背包)
It's Christmas time! PolandBall and his friends will be giving themselves gifts. There are n Balls overall. Each Ball has someone for whom he should bring a present according to some permutation p, pi原创 2017-08-09 23:36:46 · 431 阅读 · 0 评论 -
Rikka with Subset HDU - 6092 (傻瓜01背包)
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 nn positive A1−AnA1−An and their sum is mm. Then原创 2017-08-10 00:05:31 · 367 阅读 · 0 评论 -
hdu 5691 (状态压缩dp)
度度熊是他同时代中最伟大的数学家,一切数字都要听命于他。现在,又到了度度熊和他的数字仆人们玩排排坐游戏的时候了。游戏的规则十分简单,参与游戏的N个整数将会做成一排,他们将通过不断交换自己的位置,最终达到所有相邻两数乘积的和最大的目的,参与游戏的数字有整数也有负数。度度熊为了在他的数字仆人面前展现他的权威,他规定某些数字只能在坐固定的位置上,没有被度度熊限制的数字则可以自由地交换位置。 Input原创 2017-07-18 19:02:55 · 328 阅读 · 0 评论 -
qduoj no cer的一道简单签到题
no cer的一道简单签到题 发布时间: 2017年6月11日 17:59 最后更新: 2017年6月11日 18:10 时间限制: 1000ms 内存限制: 128M描述 人见人(不)爱,花见花(不)开的nr4强者Cerberux回来啦!KUCC47XNHC31WC0(CE6KQ.png他不仅回来了,还带回来了一块2*n的长板。然而他的蜜汁审美告诉他,这块长板需要贴瓷砖。但是nr4原创 2017-06-13 17:10:24 · 505 阅读 · 0 评论 -
shuoj 组装零件 状压dp 位运算得到状态的子集
零件组装 发布时间: 2017年7月9日 20:20 最后更新: 2017年7月10日 21:12 时间限制: 1000ms 内存限制: 128M描述 现有n个零件,小Y花费了很多时间来收集它们,现在他想把零件拼在一起,拼完就可以召唤神龙了。已知零件之间存在相邻的关系,拥有相邻关系的零件在最终的组装结果中就是相邻的,并且组装过程中每次只能通过相邻关系来组合零件。小Y每次可以选择两个零原创 2017-07-13 13:44:20 · 406 阅读 · 0 评论 -
hdu 5927 树形dp
Given a rooted tree with n vertices, some of the vertices are important. An auxiliary set is a set containing vertices satisfying at least one of the two conditions: ∙∙It is an important vertex ∙∙It原创 2017-07-12 17:57:05 · 572 阅读 · 0 评论 -
Animals and Puzzle codeforces 713D 二维 rmq+二分+dp(算模板了)
Owl Sonya gave a huge lake puzzle of size n × m to hedgehog Filya as a birthday present. Friends immediately started to assemble the puzzle, but some parts of it turned out to be empty — there was no p原创 2017-06-23 00:47:53 · 396 阅读 · 0 评论 -
codefroces 543A Writing Code dp优化 完全背包
Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly ai bugs in every line of原创 2017-04-30 10:28:31 · 436 阅读 · 0 评论 -
2017 山东省赛 CF 傻瓜01背包
LYD loves codeforces since there are many Russian contests. In an contest lasting for T minutes there are n problems, and for the ith problem you can get ai−di∗ti points, where ai indicates the initial原创 2017-05-09 16:43:05 · 808 阅读 · 0 评论 -
蓝桥 大臣的旅费
问题描述很久以前,T王国空前繁荣。为了更好地管理国家,王国修建了大量的快速路,用于连接首都和王国内的各大城市。为节省经费,T国的大臣们经过思考,制定了一套优秀的修建方案,使得任何一个大城市都能从首都直接或者通过其他大城市间接到达。同时,如果不重复经过大城市,从首都到达每个大城市的方案都是唯一的。J是T国重要大臣,他巡查于各大城市之间,体察民情。所以,从一个城市马不停蹄地到另一个城市成了J最常做的事情原创 2017-02-11 23:36:41 · 358 阅读 · 0 评论 -
hdu 2639 Bone Collector II DP(第i最优决策)
The title of this problem is familiar,isn’t it?yeah,if you had took part in the “Rookie Cup” competition,you must have seem this title.If you haven’t seen it before,it doesn’t matter,I will give you a原创 2017-01-19 00:14:41 · 303 阅读 · 0 评论 -
C. Mahmoud and a Message 396 div2 C dp好题
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disapp原创 2017-02-08 14:52:34 · 452 阅读 · 0 评论 -
HDU 1024 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. Given a原创 2017-01-14 17:26:41 · 807 阅读 · 0 评论 -
hdu 1078 记忆化搜索
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 Fatmou原创 2017-02-06 17:01:34 · 490 阅读 · 0 评论 -
poj 3186
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 given period t原创 2017-02-06 16:58:27 · 289 阅读 · 0 评论 -
poj 2533 最大上升子序列
A numeric sequence of ai is ordered if a1 < a2 < … < aN. Let the subsequence of the given numeric sequence ( a1, a2, …, aN) be any sequence ( ai1, ai2, …, aiK), where 1 <= i1 < i2 < … < iK <= N. For ex原创 2017-02-06 16:27:21 · 460 阅读 · 0 评论