![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
高效算法-动态规划
文章平均质量分 70
lab104_yifan
这个作者很懒,什么都没留下…
展开
-
codeforces GOOD BYE 2013
A. New Year Candlestime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputVasily the Programmer loves romance, so原创 2013-12-31 13:41:46 · 2375 阅读 · 2 评论 -
UVA 10755 - Garbage Heap(三维子矩阵最大和)
Garbage HeapTime limit: ? secondsMemory limit: 64 megabytesFarmer John has a heap of garbage formed in a rectangular parallelepiped.It consists of garbage pieces each of which has a value.原创 2014-01-20 14:35:26 · 2654 阅读 · 0 评论 -
UVA 473 - Raucous Rockers(dp)
Raucous Rockers You just inherited the rights to n previously unreleased songs recorded by the popular group Raucous Rockers. You plan to release a set of m compact disks with a selectio原创 2014-02-21 13:11:51 · 1955 阅读 · 0 评论 -
UVA 672 - Gangsters(dp)
Gangsters N gangsters are going to a restaurant. The i-th gangster comes at the time Ti and has the prosperity Pi. The door of the restaurant has K+1 states of openness expressed by th原创 2014-02-20 22:18:01 · 1389 阅读 · 0 评论 -
UVA 1292 - Strategic game(树形dp)
Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must defend a medieva原创 2014-02-23 09:29:01 · 1372 阅读 · 0 评论 -
UVA 1351 - String Compression(区间DP)
Run Length Encoding(RLE) is a simple form of compression. RLE consists of the process for searching for a repeated runs of a single character in a string to be compressed, and replacing them by a sing原创 2014-02-23 12:03:35 · 1694 阅读 · 0 评论 -
UVA 1291 - Dance Dance Revolution(dp)
Mr. White, a fat man, now is crazy about a game named ``Dance, Dance, Revolution". But his dance skill is so poor that he could not dance a dance, even if he dances arduously every time. Does ``DDR" j原创 2014-02-23 17:06:01 · 1181 阅读 · 0 评论 -
UVA 1252 - Twenty Questions(状态压缩DP+记忆化搜索)
Consider a closed world and a set of features that are defined for all the objects in the world. Each feature can be answered with ``yes" or ``no". Using those features, we can identify any object fro原创 2014-02-23 22:01:22 · 2047 阅读 · 4 评论 -
UVA 1407 - Caves(树形DP)
It is said that the people of Menggol lived in caves. A tribe's caves were connected to each other with paths. The paths were so designed that there was one and only one path to each cave. So the cave原创 2014-02-24 23:38:25 · 1464 阅读 · 0 评论 -
1427 - Parade (dp+单调队列)
Panagola, The Lord of city F likes to parade very much. He always inspects his city in his car and enjoys the welcome of his citizens. City F has a regular road system. It looks like a matrix with n +原创 2014-02-26 09:06:26 · 1252 阅读 · 0 评论 -
UVA 1394 - And Then There Was One(dp+约瑟夫环变形)
Let's play a stone removing game.Initially, n stones are arranged on a circle and numbered 1,..., n clockwise (Figure 1). You are also given two numbers k and m . From this state, remove stones on原创 2014-02-14 09:44:18 · 1515 阅读 · 0 评论 -
UVA 11825 - Hackers' Crackdown(dp+状态压缩)
Problem HHackers’ Crackdown Input: Standard InputOutput: Standard Output Miracle Corporations has a number of system services running in a distributed computer system which is a prime targ原创 2014-02-14 22:30:33 · 1273 阅读 · 0 评论 -
10859 - Placing Lampposts(树形dp)
Output: Standard OutNext Generation Contest 1 Time Limit: 2 secondsProblem DPlacing LamppostsAs a part of the mission �Beautification of Dhaka City�,原创 2014-02-15 02:55:50 · 2209 阅读 · 0 评论 -
UVA 1424 - Salesmen(dp)
Traveling salesmen of nhn. (the prestigious Korean internet company) report their current location to the company on a regular basis. They also have to report their new location to the company if th原创 2014-02-16 21:13:16 · 1098 阅读 · 0 评论 -
UVA 11552 - Fewest Flops(dp+贪心)
Problem FFEWEST FLOPSA common way to uniquely encode a string is by replacing its consecutive repeating characters (or “chunks”) by the number of times the character occurs followed by the原创 2014-02-16 23:15:27 · 1341 阅读 · 0 评论 -
11584 - Partitioning by Palindromes(dp)
We say a sequence of characters is a palindrome if it is the same written forwards and backwards. For example, 'racecar' is a palindrome, but 'fastcar' is not.A partition of a sequence of characters原创 2014-02-16 19:12:50 · 1076 阅读 · 0 评论 -
12235 - Help Bubu(状态压缩dp)
Bubu's bookshelf is in a mess! Help him!There are n books on his bookshelf. We define the mess value to be the number of segments of consecutive equal-height books. For example, if the book height原创 2014-02-28 22:59:35 · 1328 阅读 · 0 评论 -
UVA 11404 - Palindromic Subsequence(dp)
Palindromic Subsequence A Subsequence is a sequence obtained by deleting zero or more characters in a string. A Palindrome is a string which when read from left to right, reads same as w原创 2014-02-17 22:54:36 · 1389 阅读 · 0 评论 -
UVA 1099 - Sharing Chocolate(记忆化搜索+状态压缩)
Chocolate in its many forms is enjoyed by millions of people around the world every day. It is a truly universal candy available in virtually every country around the world.You find that the only th原创 2014-02-16 14:13:36 · 3005 阅读 · 2 评论 -
UVA 1169(dp + 单调队列)
Problem C - RobotruckBackgroundThis problem is about a robotic truck that distributes mail packages to several locations in a factory. The robot sits at the end of a conveyer at the mail office原创 2014-02-18 11:50:32 · 1756 阅读 · 0 评论 -
UVA 1456 - Cellular Network(dp + 贪心)
A cellular network is a radio network made up of a number of cells each served by a base station located in the cell. The base station receives call signals from mobile users (mobiles) in the cell i原创 2014-02-19 08:31:14 · 1064 阅读 · 0 评论 -
UVA 12260 - Free Goodies(dp+贪心)
Petra and Jan have just received a box full of free goodies, and want to divide the goodies between them. However, it is not easy to do this fairly, since they both value different goodies differently原创 2014-03-01 19:04:19 · 2148 阅读 · 0 评论 -
UVA 11795 - Mega Man's Mission(状态压缩dp)
BMega Man’s MissionsInputStandard InputOutputStandard Output Mega Man is off to save the world again. His objective is to kill the Robots created by原创 2014-02-20 09:37:49 · 1655 阅读 · 0 评论 -
UVA 1366 - Martian Mining(dp)
ach cell you can build either type of conveyor belt, but you cannot build both of them in the same cell. If two conveyor belts of the same type are next to each other, then they can be connected. For原创 2014-02-20 12:58:54 · 1196 阅读 · 0 评论 -
1452 - Jump(dp+约瑟夫环变形)
Integers 1, 2, 3,..., n are placed on a circle in the increasing order as in the following figure. We want to construct a sequence from these numbers on a circle. Starting with the number 1, we cont原创 2014-02-20 10:08:08 · 1603 阅读 · 0 评论 -
UVA 10688 - The Poor Giant(区间DP)
Problem AThe Poor GiantInput: Standard InputOutput: Standard OutputTime Limit: 1 secondOn a table, there are n apples, the i-th apple has the weight k+i(1<=i<=n). Exactly one of原创 2014-03-11 13:14:29 · 1050 阅读 · 0 评论 -
UVA 11456 - Trainsorting(DP + LIS)
Problem A: TrainsortingErin is an engineer. She drives trains. She also arranges the cars within each train. She prefers to put the cars in decreasing order of weight, with the heaviest car at the f原创 2014-03-11 16:15:20 · 1966 阅读 · 0 评论 -
UVA 10239 - The Book-shelver's Problem(记忆化搜索)
Problem DThe Book-shelver’s ProblemInput: standard inputOutput: standard outputTime Limit: 5 secondsMemory Limit: 32 MB You are given a collection of books, which must be shelved i原创 2014-03-12 10:40:06 · 1030 阅读 · 0 评论 -
UVA 11600 - Masud Rana(状态压缩DP+记忆化搜索)
EMasud RanaInput: Standard InputOutput: Standard Output Masud Rana, A Daring Spy Of Bangladesh Counter Intelligence. He is in a new mission. There is a total n cities i原创 2014-03-08 11:42:39 · 2819 阅读 · 2 评论 -
UVA 1474(dp + 推理)
Flatland government is building a new highway that will be used to transport weapons from its main weapon plant to the frontline in order to support the undergoing military operation against its neigh原创 2014-03-08 22:26:47 · 1263 阅读 · 0 评论 -
12222 - Mountain Road(dp+贪心)
Problem EMountain RoadIn the Franconian Switzerland, there is a narrow mountain road. With only a single lane, this is a bottleneck for two-way traffic. Your job is to schedule incoming cars原创 2014-03-15 00:04:10 · 1614 阅读 · 0 评论 -
UVA 12223 - Moving to Nuremberg(树形DP)
题目链接:12223 - Moving to Nuremberg题目大意:给定一颗无根树,有一些结点需要访问num次。然后你现在选择一个点作为起点,去访问每个点,访问完要回到原点,求一个起点,使得访问完所有点的路程最少,问这个路程,并求出这些点(如果有多个点一样小都要输出)。思路:这题是由父亲结点u的状态去推出子节点v状态。如图:dp[u]为结点u的最佳方案,num[v]为原创 2014-03-15 22:35:31 · 1588 阅读 · 0 评论 -
UVA 12105 - Bigger is Better(DP+高精度)
题目链接:12105 - Bigger is Better题意:一些火柴,问你能组成整除m最大的数字是多少。思路:dp[i][j]表示用i根火柴,组成%m余数为j的最大数字,末尾多一个数字k的状态就是dp[i + num[k]][(j * 10 + k) % m],由于最多可能50位数,所以要用高精度。注意一个优化点,由于高精度的计算上只需要乘10+k,常规的高精度乘法复杂度还是有点高原创 2014-04-30 13:51:39 · 1475 阅读 · 0 评论 -
UVA 1414 - Hanoi Towers(dp)
The ``Hanoi Towers" puzzle consists of three pegs (that we will name A , B , and C ) with n disks of different diameters stacked onto the pegs. Initially all disks are stacked onto peg A with the sm原创 2014-03-17 18:59:07 · 1207 阅读 · 0 评论 -
UVA 1484 - Alice and Bob's Trip(树形DP)
题目链接:1484 - Alice and Bob's Trip题意:BOB和ALICE这对狗男女在一颗树上走,BOB先走,BOB要尽量使得总路径权和大,ALICE要小,但是有个条件,就是路径权值总和必须在[L,R]之间,求最终这条路径的权值。思路:树形dp,dp[u]表示在u结点的权值,往下dfs的时候顺带记录下到根节点的权值总和,然后如果dp[v] + w + sum 在[l,r]内,原创 2014-04-30 16:06:44 · 1164 阅读 · 2 评论 -
UVA 10981 - String Morphing(记忆化搜索)
题目链接:10981 - String Morphing题意:给定开始的字符串,要求根据表格变化成一个字符串,问变化的顺序(注意,不一定要最少步数)思路:记忆化搜索,用map来存字符串的状态,一开始按最少步数去做TLE,其实只要找到一个符合的就可以了代码:#include #include #include #include #include using namespac原创 2014-04-30 19:39:40 · 1070 阅读 · 0 评论 -
11782 - Optimal Cut(树形DP+记忆化搜索)
题目链接:11782 - Optimal Cut题意:按前序遍历给定一棵满二叉树,现在有k次,可以选k个节点,获得他们的权值,有两个条件:1、一个节点被选了,他的子节点就不能选了。2、最终选完后,根到所有叶子的路径上,都要有一个被选的节点。思路:树形dp,dp[u][k]代表在结点u,可以选k个节点,那么就分两种情况选u节点,dp[u][k] = node[u];选子节点之原创 2014-05-01 11:29:49 · 1240 阅读 · 0 评论 -
UVA 11578 - Situp Benches(dp)
题目链接:11578 - Situp Benches题意:健♂身♂房有两个仰卧起坐坐垫,每次调整角度要花费10元/10度,每次使用要花费15,现在给定n个人的时间顺序,和所希望的角度,求最少花费思路:dp,dp[i][j][k]表示第i个人,一个角度为j,另一个为k的最小花费,一个人用和两个人用的情况分开讨论,然后记录dp状态转移路径。这个输出路径让这题变得麻烦了不少。不过机智的我还是把它原创 2014-05-01 23:43:00 · 1056 阅读 · 0 评论 -
UVA 11691 - Allergy Test(状压dp+贪心)
题目链接:11691 - Allergy Test题意:这题题意看了老半天都没弄懂,好在后面找到个PPT,上面有中文题意- -,不过上面的做法是纯贪心,挺巧妙的但是感觉有点不靠谱,下载地址:http://par.cse.nsysu.edu.tw/~advprog/advprog2011/11691.ppt給N種過敏原的存活期,每天可把一種過敏原注入人體內。若有兩個以上過敏原存活於人體中原创 2014-04-30 22:46:05 · 1825 阅读 · 0 评论 -
UVA 1534 - Taekwondo(dp)
题目链接:1534 - Taekwondo题意:两组人比赛,一组n1人,一组n2人,选择min(n1,n2)组出来,要求两两人重量差绝对值之和最小。思路:首先先预处理让n1变成人少的一组,人少的每个人都必须去匹配,dp[i][j] i表示n1组第i个人,j表示第二组多少人没匹配,于是匹配的时候n1组的第i人就和n2组的第i + j的人去匹配,然后进行状态转移dp[i][j] = {dp原创 2014-05-01 14:54:50 · 1188 阅读 · 0 评论