![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
动态规划
文章平均质量分 65
hyqsblog
这个作者很懒,什么都没留下…
展开
-
NOIP2014飞扬的小鸟
http://www.luogu.org/problem/show?pid=1941#我有话说: 这道题类似于完全背包问题。要注意细节问题。设dp(i,j)表示在坐标(i,j)时的最小点击屏幕次数。 状态转移方程: dp(i,j)=min{dp(i-1,j-x[i-1])+1,dp(i,j-x[i-1])+1,dp(i-1,j+y[i-1])};#in原创 2015-10-28 12:57:51 · 1392 阅读 · 0 评论 -
UVa1024 Fun Game
我有话说: 此题的要求是,小孩们围成环状,依次报数,男孩为B女孩为G,得到一连串字符串,求其中最小的孩子个数。 首先,我们先不要去想环状,先简化成只是一条直链形的长字符串。既然要求最小,那么我们就要考虑字符串之间的重叠。这样就可以减少字符串的长度。这样的话,我们可以先预处理掉一些被其他字符串完全包含的字符串。因为这样的串完全起不到作用。同样要预处理的是各个串之间的重叠原创 2015-07-14 18:12:14 · 1706 阅读 · 0 评论 -
1371 - Period
Given two strings A and B over an alphabet ∑ \sum , the edit distance between A and B is the minimum number of edit operations needed to convert A into B . The three edit operations are the following:原创 2015-08-07 22:49:57 · 412 阅读 · 0 评论 -
10271 - Chopsticks
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int maxn=5000+10;const int INF=1000000000;int a[maxn],dp[maxn][maxn];int main(){ int T;原创 2015-08-07 21:55:50 · 331 阅读 · 0 评论 -
UVA1336修缮长城
The Great Wall of China is truly one of the greatest wonders of the world. In 3-rd century BC, Emperor Qin Shi Huang connected the defensive structures built earlier by the states of Qin, Yan, and Zhao原创 2015-05-25 12:59:36 · 600 阅读 · 0 评论 -
12170 - Easy Climb
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=847&page=show_problem&problem=3322 Somewhere in the neighborhood we have a very nice mountain that gives a splendid vi原创 2015-06-03 13:18:50 · 437 阅读 · 0 评论 -
1628 Pizza Delivery
1628 Pizza Delivery There is a pizza house located on a straight road, and there are many houses along the road which are customers to the pizza house. To attract more orders from his customers, the原创 2015-05-17 17:15:04 · 614 阅读 · 0 评论 -
1347 - Tour
John Doe, a skilled pilot, enjoys traveling. While on vacation, he rents a small plane and starts visiting beautiful places. To save money, John must determine the shortest closed tour that connects hi原创 2015-06-23 13:23:25 · 285 阅读 · 0 评论 -
10618 - Tango Tango Insurrection
Problem A: Tango Tango Insurrection You are attempting to learn to play a simple arcade dancing game. The game has 4 arrows set into a pad: Up, Left, Down, Right. While a song plays, you watch arrows原创 2015-06-01 13:29:17 · 386 阅读 · 0 评论 -
UVA10559 Blocks
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>using namespace std;const int maxn=200+10;int n,A[maxn],d[maxn][maxn][maxn];int dp(int i,int j,int k)//表示对区间[i,j]后面还跟了k个和A原创 2015-05-31 15:30:57 · 769 阅读 · 0 评论 -
1228 - Integer Transmission
You’re transmitting an n -bits unsigned integer k through a simulated network. The i -th bit counting from left is transmitted at time i (e.g. 4-bit unsigned integer 5 is transmitted in this order: 0-1原创 2015-07-13 18:06:53 · 346 阅读 · 0 评论 -
1439 - Exclusive Access 2
Having studied mutual exclusion protocols in the previous year’s competition you are now facing a more challenging problem. You have a big enterprise system with a number concurrently running processes原创 2015-07-17 10:58:44 · 433 阅读 · 0 评论 -
12105 - Bigger is Better
Bob has n matches. He wants to compose numbers using the following scheme (that is, digit 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 needs 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 matches): Fig 1 Digits from matches Write原创 2015-07-14 21:00:24 · 270 阅读 · 0 评论 -
UVA1631 - Locker
#include #include #include #include #include #include using namespace std;const int maxn=1000+10;const int INF=100000000;char s1[maxn],s2[maxn];int cost[maxn][maxn],dp[2][maxn];void Init()原创 2015-09-15 13:18:12 · 465 阅读 · 0 评论 -
1629 - Cake slicing
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=848&problem=4504&mosmsg=Submission+received+with+ID+16048725 我有话说: 这道题的大致思想是动态规划中的记忆化搜索。求对于给定区域原创 2015-09-05 17:06:01 · 287 阅读 · 0 评论 -
UVA1630 - Folding
#include #include #include #include #include #include using namespace std;const int maxn=100+10;const int INF=1000000;int dp[maxn][maxn];string flod[maxn][maxn];string str;int judge(int L原创 2015-09-08 12:59:02 · 425 阅读 · 0 评论 -
UVA10118 - Free Candies
我有话说: 这道题比较简单,总思路就是dfs+记忆化搜索#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <vector>#include <queue>using namespace std;const int maxn=100;int n;int c原创 2015-09-01 13:00:18 · 453 阅读 · 0 评论 -
1060 搞笑世界杯
http://codevs.cn/problem/1060/ 题目描述 Description 随着世界杯小组赛的结束,法国,阿根廷等世界强队都纷纷被淘汰,让人心痛不已. 于是有人组织了一场搞笑世界杯,将这些被淘汰的强队重新组织起来和世界杯一同比赛.你和你的朋友欣然去购买球票.不过搞笑世界杯的球票出售方式也很特别,它们只准备了两种球票.A 类票——免费球票 B 类票——-双倍价钱球票.购原创 2015-08-31 13:14:13 · 491 阅读 · 0 评论 -
1380 - A Scheduling Problem
There is a set of jobs, say x1, x2,…, xn , to be scheduled. Each job needs one day to complete. Your task is to schedule the jobs so that they can be nished in a minimum number of days. There are two原创 2015-07-20 08:33:55 · 456 阅读 · 0 评论 -
1252 - Twenty Questions
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" orno”. Using those features, we can identify any object from the原创 2015-07-17 16:54:54 · 301 阅读 · 0 评论 -
12099 - The Bookcase
No wonder the old bookcase caved under the massive piles of books Tom had stacked on it. He had better build a new one, this time large enough to hold all of his books. Tom nds it practical to hav原创 2015-07-17 14:40:50 · 573 阅读 · 0 评论 -
1375 - The Best Name for Your Baby
我有话说: 个人认为这是一道比较难的动态规划题目。因为无论从状态定义,还是状态转移方程,都很抽象。求最小字典序的字符串。很醉啊。 好了,评价完了。下面讲讲解决的办法。 1.第一步,简化文法。我们把所有的转换规则都先变成S->AB这种形式。总数不超过maxn*maxlen; 2.状态定义:dp[i][L]表示符号i能变成的、长度为原创 2015-07-16 12:25:47 · 732 阅读 · 0 评论 -
1627 - Team them up!
Your task is to divide a number of persons into two teams, in such a way, that:everyone belongs to one of the teams; every team has at least one member; every person in the team knows every other per原创 2015-06-11 13:21:50 · 374 阅读 · 0 评论 -
12563 - Jin Ge Jin Qu hao
(If you smiled when you see the title, this problem is for you ^_^) For those who don’t know KTV, see: http://en.wikipedia.org/wiki/Karaoke_box There is one very popular song called Jin Ge Jin Qu(劲歌金原创 2015-06-18 13:09:34 · 398 阅读 · 0 评论 -
UVa1625 - Color Length
Cars painted in different colors are moving in a row on the road as shown in Figure 1. The color of each car is represented by a single character and the distance of two adjacent cars is assumed to be原创 2015-05-28 12:48:32 · 352 阅读 · 0 评论 -
没有上司的舞会
http://codevs.cn/problem/1380/题目描述 Description Ural大学有N个职员,编号为1~N。他们有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的直接上司。每个职员有一个快乐指数。现在有个周年庆宴会,要求与会职员的快乐指数最大。但是,没有职员愿和直接上司一起与会。输入描述 Input Description 第一行一个整数原创 2015-05-13 12:42:32 · 361 阅读 · 0 评论 -
创新吃鱼法
http://codevs.cn/problem/1773/ 题目描述 Description 回到家中的猫猫把三桶鱼全部转移到了她那长方形大池子中,然后开始思考:到底要以何种方法吃鱼呢(猫猫就是这么可爱,吃鱼也要想好吃法 ^_*)。她发现,把大池子视为01矩阵(0表示对应位置无鱼,1表示对应位置有鱼)有助于决定吃鱼策略。在代表池子的01矩阵中,有很多的正方形子矩阵,如果某个正方形子矩阵的某条对原创 2015-05-12 13:27:36 · 878 阅读 · 0 评论 -
过河 2005年NOIP全国联赛提高组
http://codevs.cn/problem/1105/ 题目描述 Description 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧。在桥上有一些石子,青蛙很讨厌踩在这些石子上。由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青蛙可能到达的点看成数轴上的一串整点:0,1,……,L(其中L是桥的长度)。坐标为0的点表示桥的起点,坐标为L的点表示桥的终点。青蛙从原创 2015-05-12 13:17:30 · 418 阅读 · 0 评论 -
加分二叉树 2003年NOIP全国联赛提高组
http://codevs.cn/problem/1090/ 题目描述 Description 设一个n个节点的二叉树tree的中序遍历为(l,2,3,…,n),其中数字1,2,3,…,n为节点编号。每个节点都有一个分数(均为正整数),记第j个节点的分数为di,tree及它的每个子树都有一个加分,任一棵子树subtree(也包含tree本身)的加分计算方法如下:subtree的左子树的加分× s原创 2015-05-12 13:09:53 · 367 阅读 · 0 评论 -
线型网络
http://codevs.cn/problem/1344/ 题目描述 Description 有 N ( <=20 ) 台 PC 放在机房内,现在要求由你选定一台 PC,用共 N-1 条网线从这台机器开始一台接一台地依次连接他们,最后接到哪个以及连接的顺序也是由你选定的,为了节省材料,网线都拉直。求最少需要一次性购买多长的网线。(说白了,就是找出 N 的一个排列 P1 P2 P3 ..PN 然原创 2015-05-10 16:00:22 · 649 阅读 · 0 评论 -
1260 快餐问题
http://codevs.cn/problem/1260/ 题目描述 Description Peter最近在R市开了一家快餐店,为了招揽顾客,该快餐店准备推出一种套餐,该套餐由A个汉堡,B个薯条和C个饮料组成。价格便宜。为了提高产量,Peter从著名的麦当劳公司引进了N条生产线。所有的生产线都可以生产汉堡、薯条和饮料,由于每条生产线每天所能提供的生产时间是有限的、不同的,而汉堡、薯条和饮料的原创 2015-05-10 16:52:03 · 692 阅读 · 0 评论 -
邮票面值设计
题目描述 Description给定一个信封,最多只允许粘贴N张邮票,计算在给定K(N+K≤40)种邮票的情况下(假定所有的邮票数量都足够),如何设计邮票的面值,能得到最大值MAX,使在1~MAX之间的每一个邮资值都能得到。例如,N=3,K=2,如果面值分别为1分、4分,则在1分~6分之间的每一个邮资值都能得到(当然还有8分、9分和12分);如果面值分别为1分、3分,则在1分~7分之间的每一个邮资值原创 2015-04-29 13:00:57 · 361 阅读 · 0 评论 -
引水入城
题目描述 Description 在一个遥远的国度,一侧是风景秀美的湖泊,另一侧则是漫无边际的沙漠。该国的行政 区划十分特殊,刚好构成一个N行M列的矩形,如上图所示,其中每个格子都代表一座城 市,每座城市都有一个海拔高度。 为了使居民们都尽可能饮用到清澈的湖水,现在要在某些城市建造水利设施。水利设施 有两种,分别为蓄水厂和输水站。蓄水厂的功能是利用水泵将湖泊中的水抽取到所在城市的 蓄水池中。因此原创 2015-04-26 15:51:56 · 403 阅读 · 0 评论 -
乌龟棋
乌龟棋http://www.codevs.cn/problem/1068/ 题目描述 Description 小明过生日的时候,爸爸送给他一副乌龟棋当作礼物。 乌龟棋的棋盘是一行N个格子,每个格子上一个分数(非负整数)。棋盘第1格是唯一 的起点,第N格是终点,游戏要求玩家控制一个乌龟棋子从起点出发走到终点。…… 1 2 3 4 5 ……N 乌龟棋中M张爬行卡片,分成4种不同的类型(M张卡片中不一原创 2015-04-04 22:03:13 · 576 阅读 · 0 评论 -
石子归并
http://codevs.cn/problem/1048/ 题目描述 Description 有n堆石子排成一列,每堆石子有一个重量w[i], 每次合并可以合并相邻的两堆石子,一次合并的代价为两堆石子的重量和w[i]+w[i+1]。问安排怎样的合并顺序,能够使得总合并代价达到最小。输入描述 Input Description 第一行一个整数n(n<=100)第二行n个整数w1,w2…wn原创 2015-05-13 12:59:28 · 218 阅读 · 0 评论 -
能量项链 2006年NOIP全国联赛提高组
http://codevs.cn/problem/1154/ 题目描述 Description 在Mars星球上,每个Mars人都随身佩带着一串能量项链。在项链上有N颗能量珠。能量珠是一颗有头标记与尾标记的珠子,这些标记对应着某个正整数。并且,对于相邻的两颗珠子,前一颗珠子的尾标记一定等于后一颗珠子的头标记。因为只有这样,通过吸盘(吸盘是Mars人吸收能量的一种器官)的作用,这两颗珠子才能聚合成原创 2015-05-15 13:25:59 · 399 阅读 · 0 评论 -
1025 - A Spy in the Metro
Secret agent Maria was sent to Algorithms City to carry out an especially dangerous mission. After several thrilling events we find her in the first station of Algorithms City Metro, examining the time原创 2015-05-17 16:53:41 · 253 阅读 · 0 评论 -
10817 - Headmaster's Headache
Problem D: Headmaster’s HeadacheTime limit: 2 secondsThe headmaster of Spring Field School is considering employing some new teachers for certain subjects. There are a number of teachers applying for t原创 2015-05-27 12:54:03 · 374 阅读 · 0 评论 -
1626 - Brackets sequence
Let us define a regular brackets sequence in the following way:Empty sequence is a regular sequence. If S is a regular sequence, then (S) and [S] are both regular sequences. If A and B are regular se原创 2015-05-17 16:20:29 · 253 阅读 · 0 评论 -
1218 - Perfect Service
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=847&page=show_problem&problem=3659 网络是由计算机通过N - 1通信链路等,任何两台电脑可以通过一个独特的沟通路线。两台电脑是相邻的如果有它们之间的通信链路。邻居的电脑电脑的设置相邻。为了快速访问和检索大量的信原创 2015-05-13 13:30:20 · 349 阅读 · 0 评论