基础DP
bootdubbo
这个作者很懒,什么都没留下…
展开
-
不同的子序列
给定一个字符串 S 和一个字符串 T,计算在 S 的子序列中 T 出现的个数。一个字符串的一个子序列是指,通过删除一些(也可以不删除)字符且不干扰剩余字符相对位置所组成的新字符串。(例如,“ACE” 是 “ABCDE” 的一个子序列,而 “AEC” 不是)题目数据保证答案符合 32 位带符号整数范围示例 1:输入:S = “rabbbit”, T = “rabbit”输出:3解释:如下图所示, 有 3 种可以从 S 中得到 “rabbit” 的方案。(上箭头符号 ^ 表示选取的字母)ra原创 2020-10-13 08:51:21 · 205 阅读 · 0 评论 -
分割回文串
题目:给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串。返回符合要求的最少分割次数。示例:输入: “aab”输出: 1解释: 进行一次分割就可将 s 分割成 [“aa”,“b”] 这样两个回文子串。dp[i]:指 s[1:i] 切割成回文串最少需要几次每次枚举 s[j:i] 是否是一个回文串,如果是 dp[i] = dp[j-1] + 1public static int minCut(String s) { int[] dp = new int[s.原创 2020-10-12 00:07:33 · 224 阅读 · 0 评论 -
E. Dreamoon and Strings
Dreamoon has a string s and a pattern string p. He first removes exactly x characters from s obtaining string s’ as a result. Then he calculates that is defined as the maximal number of non-overlappi...原创 2019-11-06 13:43:11 · 145 阅读 · 0 评论 -
超越学姐爱字符串
链接:https://ac.nowcoder.com/acm/contest/1114/A来源:牛客网超越学姐非常喜欢自己的名字,以至于英文字母她只喜欢“c”和“y”。因此超越学姐喜欢只含有“c”和“y”的字符串,且字符串中不能出现两个连续的“c”。请你求出有多少种长度为n的字符串是超越学姐喜欢的字符串。答案对1e9+7取模思路:dpdp[i][0]dp[i][0]dp[i][0]:第i个...原创 2019-10-19 08:38:38 · 240 阅读 · 0 评论 -
HDU - 3732 Ahui Writes Word【完全背包+二进制优化】
We all know that English is very important, so Ahui strive for this in order to learn more English words. To know that word has its value and complexity of writing (the length of each word does not ex...原创 2019-09-22 14:07:10 · 168 阅读 · 0 评论 -
HDU - 1712 ACboy needs your help【分组背包】
ACboy has N courses this term, and he plans to spend at most M days on study.Of course,the profit he will gain from different course depending on the days he spend on it.How to arrange the M days for ...原创 2019-09-24 11:53:35 · 168 阅读 · 0 评论 -
HDU - 3496 Watch The Movie【二维0-1背包】
New semester is coming, and DuoDuo has to go to school tomorrow. She decides to have fun tonight and will be very busy after tonight. She like watch cartoon very much. So she wants her uncle to buy so...原创 2019-09-24 13:04:30 · 161 阅读 · 0 评论 -
HDU - 1203 I NEED A OFFER!
Speakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了。要申请国外的任何大学,你都要交纳一定的申请费用,这可是很惊人的。Speakless没有多少钱,总共只攒了n万美元。他将在m个学校中选择若干的(当然要在他的经济承受范围内)。每个学校都有不同的申请费用a(万美元),并且Speakless估计了他得到这个学校offer的可能性b。不同学校之...原创 2019-09-24 13:51:13 · 625 阅读 · 0 评论 -
HDU - 3466 Proud Merchants【有序0-1背包】
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very proud even if their n...原创 2019-09-24 14:13:09 · 164 阅读 · 0 评论 -
HDU - 1864 最大报销额
现有一笔经费可以报销一定额度的发票。允许报销的发票类型包括买图书(A类)、文具(B类)、差旅(C类),要求每张发票的总额不得超过1000元,每张发票上,单项物品的价值不得超过600元。现请你编写程序,在给出的一堆发票中找出可以报销的、不超过给定额度的最大报销额。Input测试输入包含若干测试用例。每个测试用例的第1行包含两个正数 Q 和 N,其中 Q 是给定的报销额度,N(<=30)是发...原创 2019-09-24 14:39:22 · 70 阅读 · 0 评论 -
HDU - 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
急!灾区的食物依然短缺!为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都是袋装产品,其价格不等,并且只能整袋购买。请问:你用有限的资金最多能采购多少公斤粮食呢?后记:人生是一个充满了变数的生命过程,天灾、人祸、病痛是我们生命历程中不可预知的威胁。月有阴晴圆缺,人有旦夕祸福,未来对于我们而言是一个未知数。那么,我们...原创 2019-09-22 13:16:29 · 96 阅读 · 0 评论 -
HDU - 1059 Dividing【多重背包+二进制优化】
Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same v...原创 2019-09-21 21:36:59 · 134 阅读 · 0 评论 -
HDU - 2639 Bone Collector II【第k大背包】
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...原创 2019-09-21 20:47:17 · 133 阅读 · 0 评论 -
HDU - 2159 FATE【二维完全背包】
最近xhd正在玩一款叫做FATE的游戏,为了得到极品装备,xhd在不停的杀怪做任务。久而久之xhd开始对杀怪产生的厌恶感,但又不得不通过杀怪来升完这最后一级。现在的问题是,xhd升掉最后一级还需n的经验值,xhd还留有m的忍耐度,每杀一个怪xhd会得到相应的经验,并减掉相应的忍耐度。当忍耐度降到0或者0以下时,xhd就不会玩这游戏。xhd还说了他最多只杀s只怪。请问他能升掉这最后一级吗?Inpu...原创 2019-09-21 19:01:10 · 112 阅读 · 0 评论 -
CodeForces - 946D Timetable【分组背包】
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.There are m working hours during each Berl...原创 2019-09-21 11:45:11 · 201 阅读 · 0 评论 -
HDU - 3535 AreYouBusy【混合背包】
Happy New Term!As having become a junior, xiaoA recognizes that there is not much time for her to AC problems, because there are some other things for her to do, which makes her nearly mad.What’s mo...原创 2019-09-20 16:53:23 · 182 阅读 · 0 评论 -
HDU - 3033 I love sneakers!【好题】
After months of hard working, Iserlohn finally wins awesome amount of scholarship. As a great zealot of sneakers, he decides to spend all his money on them in a sneaker store.There are several brands...原创 2019-09-20 15:51:08 · 203 阅读 · 0 评论 -
分组背包问题
有 N 组物品和一个容量是 V 的背包。每组物品有若干个,同一组内的物品最多只能选一个。每件物品的体积是 vij,价值是 wij,其中 i 是组号,j 是组内编号。求解将哪些物品装入背包,可使物品总体积不超过背包容量,且总价值最大。输出最大价值。输入格式第一行有两个整数 N,V,用空格隔开,分别表示物品组数和背包容量。接下来有 N 组数据:每组数据第一行有一个整数 Si,表示第 i...原创 2019-09-20 10:37:10 · 741 阅读 · 0 评论 -
HDU - 3092 Least common multiple
Partychen like to do mathematical problems. One day, when he was doing on a least common multiple(LCM) problem, he suddenly thought of a very interesting question: if given a number of S, and we divid...原创 2019-09-24 16:06:31 · 75 阅读 · 0 评论 -
HDU - 1248 寒冰王座【完全背包】
不死族的巫妖王发工资拉,死亡骑士拿到一张N元的钞票(记住,只有一张钞票),为了防止自己在战斗中频繁的死掉,他决定给自己买一些道具,于是他来到了地精商店前.死亡骑士:“我要买道具!”地精商人:“我们这里有三种道具,血瓶150块一个,魔法药200块一个,无敌药水350块一个.”死亡骑士:“好的,给我一个血瓶.”说完他掏出那张N元的大钞递给地精商人.地精商人:“我忘了提醒你了,我们这里没有找客...原创 2019-09-24 16:21:19 · 122 阅读 · 0 评论 -
POJ - 3628 Bookshelf 2
Farmer John recently bought another bookshelf for the cow library, but the shelf is getting filled up quite quickly, and now the only available space is at the top.FJ has N cows (1 ≤ N ≤ 20) each wit...原创 2019-09-24 16:58:15 · 288 阅读 · 0 评论 -
CodeForces - 777E Hanoi Factory
Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Eg...原创 2019-10-06 22:39:17 · 145 阅读 · 0 评论 -
P1064 金明的预算方案【分组背包】
题目描述金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间金明自己专用的很宽敞的房间。更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过NN元钱就行”。今天一早,金明就开始做预算了,他把想买的物品分为两类:主件与附件,附件是从属于某个主件的,下表就是一些主件与附件的例子:主件 附件电脑 打印机,扫描仪书柜 图书书桌 台灯,文具工作椅 无如...原创 2019-09-29 17:00:12 · 117 阅读 · 0 评论 -
P1164 小A点菜
题目背景uim神犇拿到了uoi的ra(镭牌)后,立刻拉着基友小A到了一家……餐馆,很低端的那种。uim指着墙上的价目表(太低级了没有菜单),说:“随便点”。题目描述不过uim由于买了一些辅(e)辅(ro)书,口袋里只剩MM元(M \le 10000)(M≤10000)。餐馆虽低端,但是菜品种类不少,有NN种(N \le 100)(N≤100),第ii种卖a_iai 元(a_i \...原创 2019-09-29 15:44:12 · 77 阅读 · 0 评论 -
P1060 开心的金明
题目描述金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间他自己专用的很宽敞的房间。更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过NN元钱就行”。今天一早金明就开始做预算,但是他想买的东西太多了,肯定会超过妈妈限定的NN元。于是,他把每件物品规定了一个重要度,分为55等:用整数1-51−5表示,第55等最重要。他还从因特网上查到了每件物品的价格(...原创 2019-09-29 15:30:34 · 175 阅读 · 0 评论 -
Invoker
Problem Description在 dota2 中有一个叫做祈求者(Invoker)的英雄,在游戏中他有三个基础技能:冰(Quas),雷(Wex),火(Exort),每施展一个技能就可以获得相应属性的一个法球(element)。但是祈求者同时最多只能有三个法球,即如果他在有三个法球的状态下又使用了某个法球技能,那么他会获得该法球,并失去之前三个法球中最先获得的一个。不难得出,祈求者身上...原创 2019-09-28 21:17:08 · 305 阅读 · 0 评论 -
HDU - 1159 Common Subsequence
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 subseque...原创 2019-09-27 21:19:42 · 133 阅读 · 0 评论 -
HDU - 1003 Max Sum
Given a sequence a[1],a[2],a[3]…a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.InputThe first l...原创 2019-09-27 20:10:43 · 92 阅读 · 0 评论 -
POJ - 3260 The Fewest Coins
Farmer John has gone to town to buy some farm supplies. Being a very efficient man, he always pays for his goods in such a way that the smallest number of coins changes hands, i.e., the number of coin...原创 2019-09-27 17:34:13 · 177 阅读 · 0 评论 -
POJ - 1787 Charlie's Change【完全背包还原路径】
Charlie is a driver of Advanced Cargo Movement, Ltd. Charlie drives a lot and so he often buys coffee at coffee vending machines at motorests. Charlie hates change. That is basically the setup of your...原创 2019-09-27 15:54:22 · 158 阅读 · 0 评论 -
POJ - 3181 Dollar Dayz
Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on sale. During his first visit, the tools are selling variously for $1, $2, and $3. Farmer John has exactly...原创 2019-09-27 14:52:27 · 151 阅读 · 0 评论 -
POJ - 1948 Triangular Pastures【二维背包】
Like everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The old rectangular shapes are out of favor; new geometries are the favorite.I. M. Hei, the lead cow pasture archite...原创 2019-09-26 21:18:55 · 136 阅读 · 0 评论 -
POJ - 1976 A Mini Locomotive【简单DP】
A train has a locomotive that pulls the train with its many passenger coaches. If the locomotive breaks down, there is no way to pull the train. Therefore, the office of railroads decided to distribut...原创 2019-09-26 20:04:59 · 124 阅读 · 0 评论 -
POJ - 1745 Divisibility【DP好题】
Consider an arbitrary sequence of integers. One can place + or - operators between integers in the sequence, thus deriving different arithmetical expressions that evaluate to different values. Let us,...原创 2019-09-26 19:13:57 · 117 阅读 · 0 评论 -
POJ - 3624 Charm Bracelet
Bessie has gone to the mall’s jewelry store and spies a charm bracelet. Of course, she’d like to fill it with the best charms possible from the N (1 ≤ N ≤ 3,402) available charms. Each charm i in the ...原创 2019-09-24 17:12:59 · 124 阅读 · 0 评论 -
HDU - 2844 Coins【多重背包+二进制优化】
Whuacmers use coins.They have coins of value A1,A2,A3…An Silverland dollar. One day Hibix opened purse and found there were some coins. He decided to buy a very nice watch in a nearby shop. He wanted ...原创 2019-09-19 20:43:14 · 147 阅读 · 0 评论 -
HDU - 5534 Partial Tree【dp好题】
In mathematics, and more specifically in graph theory, a tree is an undirected graph in which any two nodes are connected by exactly one path. In other words, any connected graph without simple cycles...原创 2019-09-19 19:33:17 · 129 阅读 · 0 评论 -
POJ-3186 Treats for the Cows
DescriptionFJ 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 ov...原创 2019-07-12 11:51:07 · 141 阅读 · 0 评论 -
NAIPC-Mountain Scenes
/* dp[i][j]表示走到第i行时,长度为j的方案数 */#include<bits/stdc++.h>using namespace std;#define maxn 110#define mod 1000000007typedef long long ll;int n,w,h,dp[maxn][10010];int main(){ while(~scanf(...原创 2019-07-23 16:46:51 · 81 阅读 · 0 评论 -
POJ-2533 Longest Ordered Subsequence
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 < ...原创 2019-07-11 23:20:06 · 97 阅读 · 0 评论