![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
DP
文章平均质量分 69
SPZn_up
这个作者很懒,什么都没留下…
展开
-
uva 10313 Pay the Price (DP)
uva 10313 Pay the Price题目大意:现在有300种面额的硬币(1~300),给出一个金额数,问这300种面额的硬币组成该金额数的方式有多少种。注意:该题的输入有三种模式,1个数n:n为金额数;2个数n, a:n为金额数,a为硬币个数上限;3个数n, a,b:n为金额数,a b为硬币个数的下限和上限。解题思路:dp[i][j]表示面额i的金额,在硬币数不超过j的情况下,有几种组成方原创 2015-05-18 20:55:50 · 852 阅读 · 0 评论 -
uva 10271 Chopsticks (DP)
uva 10271 ChopsticksA题目大意:给出客人数K和筷子数量N(支),总人数M=客人数K + 8(还有家人)。要找出M组筷子,每组包括3支筷子,每组都有一个badness值,badness值为每组中较小的两支筷子的差值。求怎样分组,才能使总差值最小。解题思路:dp[i][j]表示使用第i支筷子,并已组成j组是的最小badness总值。在取筷子时,要注意在所有未被使用的筷子中,要有比选取原创 2015-04-08 18:50:10 · 557 阅读 · 0 评论 -
uva 10617 Again Palindrome (DP)
uva 10617 Again Palindrome题目大意:给出一段字符串,可进行删除操作,可以删除任意位置任意个数(可以是0)的字符。问,进行删除操作使原本字符串变成回文字符串,有几种方式。解题思路:dp[i][j]=1(i==j)单独一个字符也是回文字符串dp[i][j] = 1 (i == j)单独一个字符也是回文字符串s[i]!=s[j]时,dp[i][j]=dp[i+1][j]+dp[i原创 2015-04-08 21:26:28 · 566 阅读 · 0 评论 -
uva 11137 Ingenuous Cubrency (完全背包)
uva 11137 Ingenuous CubrencyPeople in Cubeland use cubic coins. Not only the unit of currency is called a cube but also the coins are shaped like cubes and their values are cubes. Coins with values of原创 2015-04-13 19:44:23 · 510 阅读 · 0 评论 -
uva 10304 Optimal Binary Search Tree (区间DP)
uva 10304 Optimal Binary Search Tree题目大意:给出N个结点(已知每个结点的权值)来建树,建树时要满足以下规则:左子树的节点的值要全小于父节点,右子树的节点的值要全大于父节点。要求最后建出的树总权值最小。总权值=各结点乘以层数(从0层开始)之后相加的和。解题思路:dp[i][j]dp[i][j]代表区间第i个结点到第j个结点组成的树最小的总权值。dp[j][i]=m原创 2015-04-07 19:25:58 · 671 阅读 · 0 评论 -
uva 10003 Cutting Sticks (DP)
uva 10003 Cutting SticksDescription你的任务是替一家叫Analog Cutting Machinery (ACM)的公司切割木棍。切割木棍的成本是根据木棍的长度而定。而且切割木棍的时候每次只切一段。很显然的,不同切割的顺序会有不同的成本。例如:有一根长10公尺的木棍必须在第2、4、7公尺的地方切割。这个时候就有几种选择了。你可以选择先切2公尺的地方,然后切4公尺的地原创 2015-03-11 20:09:44 · 787 阅读 · 0 评论 -
uva 10051 Tower of Cubes (最长上升子序列)
uva 10051 Tower of Cubes题目大意:按重量给出N个木块六个面的颜色(前后左右上下),重量逐个增加。要求满足上面的木块底部颜色与他下方的木块顶部颜色相同,并且上面的木块要比下面的木块轻,求最高可以垒几个木块。解题思路:把一个木块分成6个状态,就是一个最长上升子序列的问题。#include <cstdio>#include <cstring>#include <algorith原创 2015-04-01 21:30:48 · 528 阅读 · 0 评论 -
uva 10069 Distinct Subsequences (dp + 大数)
uva 10069 Distinct Subsequences题目大意:给出两个字符串A和B,找出A中所有与B相同的子字符串。解题思路:if(A[j−1]==B[i−1])if(A[j - 1]==B[i - 1]) { dp[i][j]=dp[i][j]+dp[i−1][j−1];dp[i][j] = dp[i][j]+dp[i - 1][j - 1];}import java原创 2015-04-01 19:13:41 · 496 阅读 · 0 评论 -
uva 590 Always on the run(dp)
uva 590 Always on the runScreeching tires. Searching lights. Wailing sirens. Police cars everywhere. Trisha Quickfinger did it again! Stealing the `Mona Lisa’ had been more difficult than planned, but原创 2015-04-01 09:54:34 · 623 阅读 · 0 评论 -
uva 11008 Antimatter Ray Clearcutting(DFS + 记忆化搜索 + 状态压缩)
uva 11008 Antimatter Ray ClearcuttingIt’s year 2465, and you are the Chief Engineer for Glorified Lumberjacks Inc. on planet Trie. There is a number of trees that you need to cut down, and the only wea原创 2015-04-20 23:37:21 · 548 阅读 · 0 评论 -
uva 10635 Prince and Princess(DP)
uva 10635 Prince and Princess(DP)In an n x n chessboard, Prince and Princess plays a game. The squares in the chessboard are numbered1, 2, 3 ... n*n, as shown below:Prince stands i原创 2015-04-25 18:50:32 · 603 阅读 · 0 评论 -
uva 10891 Game of Sum (DP)
uva 10891 Game of Sum (DP) This is a two player game. Initially there are n integer numbers in an array and playersA and B get chance to take them alternatively. Each player can take one o原创 2015-04-25 18:58:28 · 664 阅读 · 0 评论 -
uva 10401 Injured Queen Problem(DP)
uva 10401 Injured Queen Problem题目大意:这是一个变形的N皇后问题,皇后不再是占据一行一列以及斜线,她占据的只是她周围的一圈以及她所在的一列。题目给出一个含有问号,数字和字母的字符串。第i个字符是问号代表皇后在第i列的任意一行,若第i个字符是数字或字母X(1~F)代表皇后在第i列的X行。求满足该字符串的摆放方式的方法一共有几种。解题思路:从第一列开始往后递推。dp[i]原创 2015-05-20 20:57:42 · 598 阅读 · 0 评论 -
uva 10163 Storage Keepers (DP)
uva 10163 Storage Keepers有N个仓库,M个管理员,M个管理员每个人的工资都不一样,工资与他们的能力值(P)相同。一个管理员可以看管多个(n)仓库,但是仓库的安全值就会变为P / n。现在要是的最小的安全值最大,并且还要求出该状况下的最小花费。两次DP,第一次dp求出最大的最小安全值ans,第二次dp根据第一次dp求出的ans求出最小的花费。#include <cstdio>原创 2015-05-20 18:29:17 · 619 阅读 · 0 评论 -
uva 10626 Buying Coke (DP记忆化搜索)
uva 10626 Buying CokeI often buy Coca-Cola from the vending machine at work. Usually I buy several cokes at once, since my working mates also likes coke. A coke in the vending machine costs 8 Swedish c原创 2015-05-06 15:59:13 · 866 阅读 · 0 评论 -
uva 11151 Longest Palindrome (最长公共子序列)
uva 11151 Longest PalindromeA palindrome is a string that reads the same from the left as it does from the right. For example, I, GAG and MADAM are palindromes, but ADAM is not. Here, we consider also原创 2015-05-06 15:47:53 · 29390 阅读 · 0 评论 -
uva 11258 String Partition (DP)
uva 11258 String PartitionJohn was absurdly busy for preparing a programming contest recently. He wanted to create a ridiculously easy problem for the contest. His problem was not only easy, but also b原创 2015-04-28 19:09:22 · 842 阅读 · 0 评论 -
uva 10201 Adventures in Moving - Part IV (DP)
uva 10201 Adventures in Moving - Part IV题目大意:借了一辆车,车里有100单位的油。要到达N米外的目的地(每走一米消耗一个单位的油),在这一段路程中,有若干个加油站,给出的数据是每个加油站的位置和加一单位油的价格。要求到达目的地且剩下100单位油的最小消费。(到达不了则输出Impossible)解题思路:dp[i][j]数组代表的是第i个加油站油量为j的最小费原创 2015-04-28 21:28:40 · 618 阅读 · 0 评论 -
uva 10453 Make Palindrome (区间DP + 递归输出)
uva 10453 Make Palindrome 题目大意:给出一段字符串,要求求出最少加入几个字符(任意位置),可以让该字符串变成会问字符串,并输出修改以后的回文字符串。 解题思路:dp[i][j]代表了将该字符串从第i位到第j位变成回文字符串最少要添加的字符。当S[i]==S[j],dp[i][j]=dp[i+1][j−1]S[i] == S[j], dp[i][j] = dp[i + 1][原创 2015-05-11 21:13:55 · 626 阅读 · 0 评论 -
uva 10739 String to Palindrome (dp)
uva 10739 String to PalindromeIn this problem you are asked to convert a string into a palindrome with minimum number of operations. The operations are described below:Here you’d have the ultimate free原创 2015-04-06 19:51:03 · 380 阅读 · 0 评论 -
uva 10651 Pebble Solitaire (BFS)
uva 10651 Pebble SolitairePebble solitaire is an interesting game. This is a game where you are given a board with an arrangement of small cavities, initially all but one occupied by a pebble each. The原创 2015-03-31 19:56:45 · 561 阅读 · 0 评论 -
uva 10404 Bachet's Game (完全背包+博弈)
uva 10404 Bachet’s GameBachet’s game is probably known to all but probably not by this name. Initially there are n stones on the table. There are two players Stan and Ollie, who move alternately. Stan原创 2015-03-23 20:23:59 · 585 阅读 · 0 评论 -
uva 10066 The Twin Towers (最长公共子序列)
uva 10066 The Twin Towers题目大意:最长公共子序列。 解题思路:最长公共子序列。#include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>using namespace std;int a[105], b[105], dp[105][105];int main() {原创 2015-03-14 18:38:09 · 692 阅读 · 0 评论 -
uva 531 Compromise (最长公共子序列)
uva 531 CompromiseIn a few months the European Currency Union will become a reality. However, to join the club, the Maastricht criteria must be fulfilled, and this is not a trivial task for the countri原创 2015-03-20 19:17:36 · 653 阅读 · 0 评论 -
uva 10534 Wavio Sequence (最长上升子序列)
uva 10534 Wavio SequenceWavio is a sequence of integers. It has some interesting properties. · Wavio is of odd length i.e. L = 2*n + 1. · The first (n+1) integers of Wavio sequence makes原创 2015-03-25 20:56:29 · 584 阅读 · 0 评论 -
uva 507 Jill Rides Again (DP)
uva 507 Jill Rides Again Jill likes to ride her bicycle, but since the pretty city of Greenhills where she lives has grown, Jill often uses the excellent public bus system for part of her jo原创 2015-03-03 22:33:35 · 598 阅读 · 0 评论 -
uva 562 Dividing coins (01背包)
uva 562 Dividing coins It's commonly known that the Dutch have invented copper-wire. Two Dutch men were fighting over a nickel, which was made of copper. They were both so eager to get it an原创 2015-03-15 19:55:33 · 565 阅读 · 0 评论 -
uva 10192 Vacation(最长公共子序列)
uva 10192 VacationThe ProblemYou are planning to take some rest and to go out on vacation, but you really don’t know which cities you should visit. So, you ask your parents for help. Your mother says “原创 2015-03-15 14:08:24 · 639 阅读 · 0 评论 -
uva 825 Walking on the Safe Side (dp)
uva 825 Walking on the Safe SideSquare City is a very easy place for people to walk around. The two-way streets run North-South or East-West dividing the city into regular blocks. Most street intersect原创 2015-03-24 21:07:29 · 681 阅读 · 0 评论 -
uva 357 Let Me Count The Ways (DP)
uva 357 Let Me Count The WaysAfter making a purchase at a large department store, Mel's change was 17 cents. He received 1 dime, 1 nickel, and 2 pennies. Later that day, he was shopping at a c原创 2015-03-15 14:57:04 · 685 阅读 · 0 评论 -
uva 111 History Grading(DP初步应用)
uva 111 History GradingMany problems in Computer Science involve maximizing some measure according to constraints.Consider a history exam in which students are asked to put several histori原创 2015-01-13 21:49:42 · 526 阅读 · 0 评论 -
uva 10130 SuperSale (01背包)
uva 10130 SuperSale题目大意:每组数据包括两个部分:1)货物的价值及重量 2)每个人的最大负重量。要求这些人所能带走的最大价值。解题思路:要注意的一点是,货物是有无限的,也就是不同的人可以拿相同的货物,所以这题可以转换为01背包。把每个人的最大负重当成背包的大小,求每个人的最优解,最后相加就是答案。#include <cstdio>#include <cstring>#incl原创 2015-03-20 19:27:59 · 648 阅读 · 0 评论 -
uva 10465 Homer Simpson (完全背包)
uva 10465 Homer Simpson题目大意:有两种汉堡,给出吃每种汉堡的时间,以及总时间。求出在充分利用时间的前提下,能吃的最多的汉堡数量。当无法利用所有时间时,再在汉堡数量后面输出剩余的时间。解题思路:完全背包。#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <cst原创 2015-03-20 21:09:17 · 679 阅读 · 0 评论 -
uva 10285 Longest Run on a Snowboard (记忆化搜索)
uva 10285 Longest Run on a Snowboard题目大意:给出一张n*m的雪地地图,每格标注的是该点的高度。从地势高的地方可以滑到地势低的地方(只能上下左右滑),问最长的滑雪距离。解题思路:逐一访问各点,若该点没有被访问过,则进行DFS找出该点为滑雪起始点的最长滑雪距离,用dp数组记录,若该点已被访问过,则返回其对应的dp数组记录的值。#include <cstdio>#i原创 2015-03-21 18:54:45 · 743 阅读 · 0 评论 -
uva 10564 Paths through the Hourglass (DP)
uva 10564 Paths through the HourglassPaths through the HourglassInput: Standard Input Output: Standard Output Time Limit: 2 Seconds In the hourglass to the right a path is marked. A path原创 2015-03-13 20:31:47 · 550 阅读 · 0 评论 -
uva 103 Stacking Boxes (DAG)
uva 103 Stacking BoxesBackgroundSome concepts in Mathematics and Computer Science are simple in one or two dimensions but become more complex when extended to arbitrary dimensions. Consider solving dif原创 2015-03-10 21:01:46 · 676 阅读 · 0 评论 -
uva 437 The Tower of Babylon (DAG)
uva 437 The Tower of BabylonPerhaps 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 con原创 2015-03-22 20:49:05 · 715 阅读 · 0 评论 -
uva 10131 Is Bigger Smarter? (DAG)
uva 10131 Is Bigger Smarter?题目大意:当一只大象的体重大于另一只的体重,且智商小于另一只的智商,该大象便可以“嵌套”另一只大象。问,最长的嵌套方式。(答案不唯一)解题思路:DAG。#include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>using namespace std;原创 2015-03-14 17:54:35 · 574 阅读 · 0 评论 -
uva 116 Unidirectional TSP (DP)
uva 116 Unidirectional TSPBackgroundProblems that require minimum paths through some domain appear in many different areas of computer science. For example, one of the constraints in VLSI routing probl原创 2015-03-12 19:53:07 · 644 阅读 · 0 评论 -
uva 674 Coin Change (DP)
uva 674 Coin ChangeSuppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money.For example, if we have 11 cen原创 2015-03-11 18:11:41 · 682 阅读 · 0 评论