![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
DP
文章平均质量分 79
hyesuixin
这个作者很懒,什么都没留下…
展开
-
POJ__2955 Brackets
题目描述: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] are reg原创 2017-07-12 18:42:13 · 170 阅读 · 0 评论 -
HYSBZ - 1090 字符串折叠(正常的区间DP)
折叠的定义如下: 1. 一个字符串可以看成它自身的折叠。记作S S 2. X(S)是X(X>1)个S连接在一起的串的折叠。记作X(S) SSSS…S(X个S)。 3. 如果A A’, BB’,则AB A’B’ 例如,因为3(A) = AAA, 2(B) = BB,所以3(A)C2(B) AAACBB,而2(3(A)C)2(B)AAACAAACBB 给一个字符串,求它的最短折叠。例如AAAAAAAAAABABABCCD的最短折叠为:9(A)3(AB)CCD。原创 2017-09-04 20:06:18 · 201 阅读 · 0 评论 -
HDU - 6170 Two strings (多校,DP,字符串匹配)
Giving two strings and you should judge if they are matched. The first string contains lowercase letters and uppercase letters. The second string contains lowercase letters, uppercase letters, and special symbols: “.” and “*”. . can match any letter, an原创 2017-08-23 10:56:24 · 261 阅读 · 0 评论 -
HDU - 5492 Find a path (推公式+暴力DP 15年ICPC合肥网赛)
题目描述:点击打开链接题意,给你一张N*M表格,表格的每一个点都有一个数。你需要从表格的左上角走到表格的右下角,每次只能朝下或者朝右走,这样走到右下角之后会形成一条长度为(N+M-1)的路径,将这路径经过的所有数形成一个(N+M-1)的数列,你需要按题中给出的计算式算出一个值,你需要保证所求的值最小。对于这种题给人的第一反应就是DP,但是题目给的式子无法设计状态进行状态转移,那么我原创 2017-09-13 23:08:48 · 262 阅读 · 0 评论 -
HDU - 3182 Hamburger Magi (坑了我一天的简单DP!!!)
In the mysterious forest, there is a group of Magi. Most of them like to eat human beings, so they are called “The Ogre Magi”, but there is an special one whose favorite food is hamburger, having been jeered by the others as “The Hamburger Magi”. Let’s gi原创 2017-09-06 20:47:59 · 273 阅读 · 0 评论 -
POJ - 3254 Corn Fields(灵活运用状态压缩)
Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of squares. Regrettably, some of the squares are infertile and can't be planted.原创 2017-09-07 21:18:00 · 242 阅读 · 0 评论 -
codeforces Gym - 101485 D Debugging (2015-2016 Northwestern European Regional Contest (NWERC 2015))
题目描述:点击打开链接这题题意其实很不好理解,你有一个n行的程序,现在程序运行了r时间之后停止了运行,证明此处有一个bug,现在你需要在程序中加printf来调试找到bug所在的位置,你每次加一个printf所需的时间为p,为你在最坏的情况下最少需要多少时间找到bug。首先考虑何为最坏情况,我理解的是,无论此时你在哪里加了一个printf你的程序都需要再运行r时间,也就是说无论你怎原创 2017-09-15 22:43:02 · 588 阅读 · 0 评论 -
HDU - 5534 Partial Tree(2015 ICPC 长春,感觉应该是一个早就应该会的简单DP技巧)
题目描述:点击打开链接要你构造一棵结点数为n的树,给了结点度数为i是可以得到的分数vi,现在要求你构造的这棵树能够得到的分数最大。这个问题看起来有点复杂,我们可以把这个问题转换一下,首先如果要构造一棵树的话,那么所有结点的总度数一定为2*n-2,我们可以把不同度数不同分数的结点看作n-1种不同的结点,那么实际上我们要做的工作就是把这2*n-2度分配给这n-1种不同的结点从而得到最大的分原创 2017-09-25 21:23:57 · 237 阅读 · 0 评论 -
CodeForces - 687C The Values You Can Make (简单DP)
题目描述:点击打开链接题意给n个数,要你用这n个数去凑成K,然后每种能凑成K的方案作为一个集合,要你把所有集合的所有子集的数求和,统计不同和的数目并且依次输出。关于凑成K的方案部分用DP去处理dp[i][j]表示能否用j去凑出i,这样定义状态的方便之处在于因为一旦j可以凑成K的话,那么j这个数一定是某个符合条件的集合的子集的数之和。然后进行状态转移时,首先枚举每个数,为了避免每个数原创 2017-11-06 21:50:03 · 247 阅读 · 0 评论 -
CodeForces - 191A Dynasty Puzzles(简单DP)
题目描述:点击打开链接题目比较长但是题意却没有很复杂,现给你n个字符串,如果一个字符串的尾与另一个字符串的首相同,那么这两个字符串就可以相连,要求的是最长的首尾相同的字符串长度。定义dp[i][j]表示以i开头以j结尾的字符串的最长长度,那么对于n个字符串我们只考虑将它连到前面的字符串上,所以状态转移就简单的多了,枚举已经连接的最长长度去更新就好了。AC代码:#includ原创 2017-10-14 17:16:25 · 281 阅读 · 0 评论 -
HDU 4427 Math Magic (优化DP,ICPC2012长春)
题目描述:点击打开链接题意要用K个数组成和为N并且LCM为M的方案数,最直接的想法dp[i][j][k]表示i个数和为j并且LCM为k时方案数,由于要最后的LCM为M所以你用来组合的数都必须是M的约数,所以就先预处理出M的约数然后状态转移dp[i+1][[j+x][lcm[x,p]]=sum(dp[i][j][p])(x表示M的某个约数)。但是我这个题错了N种错法才A,首先MLE然后换滚动原创 2017-11-21 21:35:16 · 213 阅读 · 0 评论 -
HYSBZ - 1055 玩具取名 (十分暴力的DP)
某人有一套玩具,并想法给玩具命名。首先他选择WING四个字母中的任意一个字母作为玩具的基本名字。然后他会根据自己的喜好,将名字中任意一个字母用“WING”中任意两个字母代替,使得自己的名字能够扩充得很长。现在,他想请你猜猜某一个很长的名字,最初可能是由哪几个字母变形过来的。原创 2017-09-04 19:02:50 · 256 阅读 · 0 评论 -
HDU - 2476 String painter (区间DP,08成都现场赛题)
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 characters of a string to any other character you want. That原创 2017-09-04 11:01:31 · 278 阅读 · 0 评论 -
HDU - 3905 Sleeping (状态有点麻烦的DP)
ZZZ is an enthusiastic ACMer and he spends lots of time on training. He always stays up late for training. He needs enough time to sleep, and hates skipping classes. So he always sleeps in the class. With the final exams coming, he has to spare some time t原创 2017-09-04 10:04:14 · 189 阅读 · 0 评论 -
POJ __2923 Relocation
题目描述;Emma and Eric are moving to their new house they bought after returning from their honeymoon. Fortunately, they have a few friends helping them relocate. To move the furniture, they only have原创 2017-07-13 20:37:54 · 254 阅读 · 0 评论 -
UVA 11584 Partitioning by Palindromes
We say a sequence of charactersis a palindrome if itis the same written forwardsand backwards. For example,‘racecar’ is a palindrome, but‘fastcar’ is not.A partition of a sequence ofcharacters is a list of one ormore disjoint non-empty groupsof co原创 2017-07-16 08:51:47 · 153 阅读 · 0 评论 -
POJ_1088 滑雪
Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子原创 2017-07-16 09:01:02 · 199 阅读 · 0 评论 -
UVA 10003 Cutting Sticks
题目描述:点击打开链接非常典型的区间DP,枚举区间长度i,枚举起点j然后确定终点r,之后枚举区间分割点k来更新状态,dp[j][r]=min(dp[j][r],dp[j][k]+dp[k][r]+x),x为此时分割的长度。 #include<iostream>#include<cstdio>#include<cstring>#includ...原创 2017-07-16 09:11:10 · 180 阅读 · 0 评论 -
HDU 5067 Harry And Dig Machine
题目描述:点击打开链接地图上有k个点必须走,而且最后要走回起点,这题或许可以用BFS写?没试过,我在这里用的是DP的写法,不过无论是BFS或者DP,核心还是状态压缩,我觉得状态压缩的题数据一般会有十分明显的提示,通常是有一些的物品的处理情况非常多,但是这种特殊物品的数量又特别少,通常是不超过20,这种时候一般都采取状态压缩的方式,将状态简化之后这题其实是一个非常清晰的关于最短路径的DP,算...原创 2017-07-16 09:24:54 · 270 阅读 · 0 评论 -
UVA 116 Unidirectional TSP
Problems that require minimum paths through some domain appear in many different areas of computerscience. For example, one of the constraints in VLSI routing problems is minimizing wire length. TheTraveling Salesperson Problem (TSP) — finding whether al原创 2017-07-16 09:52:52 · 204 阅读 · 0 评论 -
UVA - 1347 Tour (双调旅行商问题)
John Doe, a skilled pilot, enjoys traveling. While on vacation, he rents a small plane and starts visitingbeautiful places. To save money, John must determine the shortest closed tour that connects hisdestinations. Each destination is represented by a po原创 2017-08-08 09:41:23 · 353 阅读 · 0 评论 -
UVA__The Tower of Babylon
题目描述:Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the educational nature of this contest, we will tell y原创 2017-07-12 16:51:24 · 180 阅读 · 0 评论 -
HDU - 6143 Killer Names (多校训练,DP)
> Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith Lord Darth Vader. A powerful Force-user who lived during the era of the Galactic Empire, Marek originated from the Wookiee home planet of Kashyyyk as the sole offspring of two Jed原创 2017-08-18 15:17:44 · 195 阅读 · 0 评论 -
LightOJ - 1033 Generating Palindromes(区间DP)
By definition palindrome is a string which is not changed when reversed. "MADAM" is a nice example of palindrome. It is an easy job to test whether a given string is a palindrome or not. But it may not be so easy to generate a palindrome.Here we will mak原创 2017-09-03 19:49:25 · 191 阅读 · 0 评论 -
LightOJ - 1295 Lighting System Design(简单的DP)
You are given the task to design a lighting system for a huge conference hall. After doing a lot of calculation & sketching, you have figured out the requirements for an energy-efficient design that can properly illuminate the entire hall. According to you原创 2017-09-03 20:46:15 · 231 阅读 · 0 评论 -
URAL - 1036 Lucky Tickets(DP+大数)
题目描述:点击打开链接题意:一个2*N位的数要保证前N位数的和与后N位相等,并且这2*N位的和为s,求这样的数有多少个,首先s为奇数的时候答案肯定为0,然后s为偶数的时候那就是一个N位数和为s/2的方案数,简单DP,dp[i][j]表示i位数和为j的方案数进行状态转移即可,题目数据很大要用大数。AC代码:#include#include#include#include#原创 2017-12-04 20:08:49 · 323 阅读 · 0 评论