
背包问题DP
爱上键盘的小哥哥
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
B-number (数位DP)
A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- string "13" and can be divided by 13. For example, 130 and 2613 are wqb-numbers, but 143 and 2639 ar原创 2017-10-04 19:18:47 · 792 阅读 · 0 评论 -
Bomb (数位DP)
The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the current number sequence inc原创 2017-10-04 20:06:04 · 383 阅读 · 0 评论 -
zb的生日
描述 今天是阴历七月初五,acm队员zb的生日。zb正在和C小加、never在武汉集训。他想给这两位兄弟买点什么庆祝生日,经过调查,zb发现C小加和never都很喜欢吃西瓜,而且一吃就是一堆的那种,zb立刻下定决心买了一堆西瓜。当他准备把西瓜送给C小加和never的时候,遇到了一个难题,never和C小加不在一块住,只能把西瓜分成两堆给他们,为了对每个人都公平,他想让两堆的重量之差最小。每个西瓜的原创 2017-10-21 17:24:07 · 160 阅读 · 0 评论 -
龟兔赛跑 (DP)
据说在很久很久以前,可怜的兔子经历了人生中最大的打击——赛跑输给乌龟后,心中郁闷,发誓要报仇雪恨,于是躲进了杭州下沙某农业园卧薪尝胆潜心修炼,终于练成了绝技,能够毫不休息得以恒定的速度(VR m/s)一直跑。兔子一直想找机会好好得教训一下乌龟,以雪前耻。最近正值HDU举办50周年校庆,社会各大名流齐聚下沙,兔子也趁此机会向乌龟发起挑战。虽然乌龟深知获胜希望不大,不过迫于舆论压力,只能接受挑原创 2017-10-13 11:23:58 · 384 阅读 · 0 评论 -
完全背包
描述 直接说题意,完全背包定义有N种物品和一个容量为V的背包,每种物品都有无限件可用。第i种物品的体积是c,价值是w。求解将哪些物品装入背包可使这些物品的体积总和不超过背包容量,且价值总和最大。本题要求是背包恰好装满背包时,求出最大价值总和是多少。如果不能恰好装满背包,输出NO输入第一行: N 表示有多少组测试数据(N接下来每组测试数据的第一行有两个整数M,V。 M表示物品种类的数目,原创 2017-11-21 10:57:50 · 192 阅读 · 0 评论 -
一卡通大冒险(HDU2512)
Problem Description因为长期钻研算法, 无暇顾及个人问题,BUAA ACM/ICPC 训练小组的帅哥们大部分都是单身。某天,他们在机房商量一个绝妙的计划"一卡通大冒险"。这个计划是由wf最先提出来的,计划的内容是,把自己的联系方式写在校园一卡通的背面,然后故意将自己的卡"遗失"在某处(如水房,TD,食堂,主M。。。。)他们希望能有MM看到他们遗失卡,能主动跟他们联系,这样就有原创 2017-12-26 16:49:29 · 293 阅读 · 0 评论 -
最长回文子串
回文串是指aba、abba、cccbccc、aaaa这种左右对称的字符串。输入一个字符串Str,输出Str里最长回文子串的长度。Input 输入Str(Str的长度 Output 输出最长回文子串的长度L。 Sample Input daabaacSample Output 5代码:dp[j][i] j到i是回文字符串#include#include#i原创 2018-01-23 17:23:59 · 252 阅读 · 0 评论 -
919D. Substring(拓扑排序+dp)
You are given a graph with n nodes and m directed edges. One lowercase letter is assigned to each node. We define a path's value as the number of the most frequently occurring letter. For example, if ...原创 2018-02-13 22:29:45 · 344 阅读 · 0 评论 -
934 C. A Twisty Movement
A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying d...原创 2018-02-17 10:57:20 · 363 阅读 · 0 评论 -
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]...原创 2018-02-20 16:26:21 · 325 阅读 · 0 评论 -
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 eq...原创 2018-02-20 17:13:55 · 404 阅读 · 0 评论 -
String painter (区间dp)
There 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 change a segment of cha...原创 2018-02-24 10:38:32 · 245 阅读 · 0 评论 -
凑零钱(背包)
韩梅梅喜欢满宇宙到处逛街。现在她逛到了一家火星店里,发现这家店有个特别的规矩:你可以用任何星球的硬币付钱,但是绝不找零,当然也不能欠债。韩梅梅手边有104枚来自各个星球的硬币,需要请你帮她盘算一下,是否可能精确凑出要付的款额。输入格式:输入第一行给出两个正整数:N(<=104)是硬币的总个数,M(<=102)是韩梅梅要付的款额。第二行给出N枚硬币的正整数面值。数字间以空格分隔。输出...原创 2018-03-13 16:20:41 · 783 阅读 · 0 评论 -
Doing Homework (DP)
Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every teacher gives him a deadline of handing in the homework. If Ignatius hands in the homework after ...转载 2018-05-17 16:41:16 · 318 阅读 · 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 sequen...原创 2018-05-17 17:07:57 · 1338 阅读 · 0 评论 -
Good Numbers (数位DP)
If we sum up every digit of a number and the result can be exactly divided by 10, we say this number is a good number.You are required to count the number of good numbers in the range from A to B,原创 2017-10-04 18:18:24 · 591 阅读 · 0 评论 -
数组的最大代价
数组A包含N个元素A1, A2......AN。数组B包含N个元素B1, B2......BN。并且数组A中的每一个元素Ai,都满足1 (公式表示所有两个相邻元素的差的绝对值之和)给出数组B,计算可能的最大代价S。Input 第1行:1个数N,表示数组的长度(1 第2 - N+1行:每行1个数,对应数组元素Bi(1 Output 输出最大代价S。 Sample原创 2017-10-27 12:05:39 · 212 阅读 · 0 评论 -
Common Subsequence (LCS)
A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = < x1, x2, ..., xm > another sequence Z = < z1, z2, ..., zk > is a ...原创 2017-08-16 14:59:21 · 234 阅读 · 0 评论 -
Ignatius and the Princess IV(暴力)
"OK, you are not too bad, em... But you can never pass the next test." feng5166 says."I will tell you an odd number N, and then N integers. There will be a special integer among them, you have t原创 2017-08-17 13:58:56 · 759 阅读 · 0 评论 -
Piggy-Bank (完全背包)
Before ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action comes from Irreversibly Bound Money (IBM). The idea behind is simple原创 2017-08-17 16:29:15 · 505 阅读 · 0 评论 -
Vacations(DP)
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of thisn days: whether that gym opened and whether a contest was原创 2017-08-17 19:58:45 · 359 阅读 · 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.T原创 2017-08-18 12:23:48 · 356 阅读 · 0 评论 -
Monkey and Banana (最长子序列)
A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monk原创 2017-08-18 17:49:46 · 252 阅读 · 0 评论 -
Elimination(DP)
The finalists of the "Russian Code Cup" competition in 2214 will be the participants who win in one of the elimination rounds.The elimination rounds are divided into main and additional. Each of the原创 2017-08-18 20:11:28 · 439 阅读 · 0 评论 -
饭卡(01背包)
电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够)。所以大家都希望尽量使卡上的余额最少。某天,食堂中有n种菜出售,每种菜可购买一次。已知每种菜的价格以及卡上的余额,问最少可使卡上的余额为多少。 Input 多组数据。对于每组数据: 第一原创 2017-08-14 15:38:12 · 186 阅读 · 0 评论 -
Bone Collector(01背包问题)
Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave …The bone collect原创 2017-08-14 16:48:11 · 299 阅读 · 0 评论 -
Big Event in HDU(多重背包问题)
Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002.原创 2017-08-15 14:10:32 · 379 阅读 · 0 评论 -
数塔 (dp)
在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少? 已经告诉你了,这是个DP的题目,你能AC吗? Input 输入数据首先包括一个整数C,表示测试实例的个数,每个测试实例的第一行是一个整数N(1 <= N <= 100),表示数塔的高度,接下来用N行数字原创 2017-08-15 14:59:46 · 479 阅读 · 0 评论 -
Longest Ordered Subsequence(dp)
A numeric sequence of ai is ordered ifa1 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 examp原创 2017-08-15 16:19:41 · 289 阅读 · 0 评论 -
子序列个数 (DP)
子序列的定义:对于一个序列a=a1,a2,......an。则非空序列a'=ap1,ap2......apm为a的一个子序列,其中1例如4,14,2,3和14,1,2,3都为4,13,14,1,2,3的子序列。对于给出序列a,有些子序列可能是相同的,这里只算做1个,请输出a的不同子序列的数量。由于答案比较大,输出Mod 10^9 + 7的结果即可。Input 第1行:一个数N,原创 2017-08-25 14:29:57 · 1346 阅读 · 0 评论 -
免费馅饼 (dp)
都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼。说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内。馅饼如果掉在了地上当然就不能吃了,所以gameboy马上卸下身上的背包去接。但由于小径两侧都不能站人,所以他只能在小径上接。由于gameboy平时老呆在房间里玩游戏,虽然在游戏中是个身手敏捷的高手,但在现实中运动神经特别迟钝原创 2017-08-15 19:51:07 · 233 阅读 · 0 评论 -
命运 (DP方格取数)
穿过幽谷意味着离大魔王lemon已经无限接近了! 可谁能想到,yifenfei在斩杀了一些虾兵蟹将后,却再次面临命运大迷宫的考验,这是魔王lemon设下的又一个机关。要知道,不论何人,若在迷宫中被困1小时以上,则必死无疑!可怜的yifenfei为了去救MM,义无返顾地跳进了迷宫。让我们一起帮帮执着的他吧! 命运大迷宫可以看成是一个两维的方格阵列,如下图所示: yifen原创 2017-08-15 21:03:30 · 278 阅读 · 0 评论 -
Phalanx (DP)
Today is army day, but the servicemen are busy with the phalanx for the celebration of the 60th anniversary of the PRC. A phalanx is a matrix of size n*n, each element is a character (a~z or A~Z), ...原创 2018-05-17 18:39:41 · 367 阅读 · 0 评论