![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
dp
文章平均质量分 70
Dijkstra__
这个作者很懒,什么都没留下…
展开
-
poj1837
BalanceTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 13489 Accepted: 8455DescriptionGigel has a strange "balance" and he wants to poise it. Actually转载 2016-08-06 13:42:40 · 927 阅读 · 0 评论 -
BUCT OJ 分解式的个数
题目描述大于1的正整数可以分解成一组因子的乘积,例如12可以分解成:12、6*2、4*3、3*4、3*2*2、2*6、2*3*2、2*2*3,共8个分解式。请设计算法,计算指定的大于1的正整数的分解式的个数。输入第一行为测试用例个数n,n≤100000。 从第二行开始,共有n行,每行为一个大于1的正整数m,m≤10001。输出对每个测试用例m,输出其分解式的原创 2016-12-13 23:44:29 · 1190 阅读 · 0 评论 -
UVA 1625 Color Length
Problem Description输入两个颜色序列,要求按顺序合并成一个序列,即每次把一个序列的开头的颜色放到新序列的尾部。对于每个颜色c来说,其跨度l(c),表示c的最大位置和最小位置的差。你的任务是找一种合并方式使得所有l(c)的总和最小。dp[i][j]表示第一个串移走了i个元素,第二个串移走了j个元素还需要多少费用。dp[i][j]表示的是,当序列1取了原创 2016-11-25 10:34:35 · 905 阅读 · 0 评论 -
UVA 11584 Partitioning by Palindromes
题目大意:输入一个只有小写字母组成的字符串,你的任务是把它划分成尽量少的回文串。思路:dp[i]=min(dp[j]+1)(j+1~i的字符串是回文串)事先处理出第i到j的位置的字符串是否回文串#include#include#include#include#include#include#include#include#include#include#includ原创 2016-11-25 10:18:14 · 1019 阅读 · 0 评论 -
UVA 11400 Lighting System Design
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 c原创 2016-11-25 10:10:17 · 1142 阅读 · 0 评论 -
UVA 12563 Jin Ge Jin Qu hao
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原创 2016-11-25 09:51:32 · 1244 阅读 · 0 评论 -
UVA 116 Unidirectional TSP
BackgroundProblems that require minimum paths through some domain appear in many different areas of computer science. For example, one of the constraints in VLSI routing problems is minimizing wir原创 2016-11-25 09:40:47 · 986 阅读 · 0 评论 -
poj 1947 Rebuilding Roads
The cows have reconstructed Farmer John's farm, with its N barns (1 <= N <= 150, number 1..N) after the terrible earthquake last May. The cows didn't have time to rebuild any extra roads, so now there原创 2016-12-07 11:35:20 · 1006 阅读 · 0 评论 -
uva1347 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 h原创 2016-11-24 00:08:45 · 1093 阅读 · 0 评论 -
BUCT OJ 矩阵最优连乘问题
题目描述已知一组连乘矩阵的各维长度,要求计算并输出计算量最小的计算顺序表达式。输入每行为一组连乘矩阵的各维长度,行中第一个数字是连乘矩阵的个数n,n≤100,后面是n+1个维长。 矩阵个数为0表示输入结束。输出对每行输入,计算最优计算顺序,并以括号形式将计算表达式输出,各矩阵用A0, A1, ..的形式表示。样例输入1 10 202 10 2原创 2016-12-13 23:49:06 · 1635 阅读 · 0 评论 -
poj3267
这个题是关于字符串匹配的dp。The Cow LexiconTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 10561 Accepted: 5070DescriptionFew know that the cows have their o原创 2017-04-07 10:51:33 · 668 阅读 · 0 评论 -
hdu6092 Rikka with Subset
Rikka with SubsetTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 997 Accepted Submission(s): 493Problem DescriptionAs we know原创 2017-08-09 11:08:20 · 989 阅读 · 0 评论 -
hdu 1074 Doing Homework
二进制状态压缩dp,第一次接触这个算法,同时吐槽一下自己:自己之前写博客从来不加注释,觉得自己会就OK了,博客是给自己看的,从没注意过看我博客的人的想法。 然而既然别人看你博客,那肯定是要学习你会然而别人不会的知识,如果不加注释的话,别人肯定看不懂,浪费别人的时间。自己写这道题深有体会, 看了好多大牛的博客,然而他们好多没加注释,搞得我根本就不知道他们写的是什么,自己想这道题想了好久,最后找到转载 2017-07-06 11:17:10 · 850 阅读 · 0 评论 -
codeforces711c Coloring Trees
C. Coloring Treestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputZS the Coder and Chris the Baboon has arr原创 2017-04-17 16:29:41 · 1186 阅读 · 0 评论 -
poj1080
Human Gene FunctionsTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 19561 Accepted: 10911DescriptionIt is well known that a human gene can be considered原创 2017-04-13 23:38:39 · 1432 阅读 · 0 评论 -
poj
Cow BowlingTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 18716 Accepted: 12463DescriptionThe cows don't use actual bowling balls when they go bowling.原创 2017-04-13 23:35:32 · 962 阅读 · 0 评论 -
poj2533
Longest Ordered SubsequenceTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 51188 Accepted: 22754DescriptionA numeric sequence of ai is ordered if a1 a2原创 2017-04-13 23:25:03 · 935 阅读 · 0 评论 -
poj1260
PearlsTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 9229 Accepted: 4655DescriptionIn Pearlania everybody is fond of pearls. One company, called The原创 2017-04-13 23:21:16 · 1072 阅读 · 0 评论 -
poj 1836
AlignmentTime Limit: 1000MS Memory Limit: 30000KTotal Submissions: 16877 Accepted: 5517DescriptionIn the army, a platoon is composed by n soldiers. During the m原创 2017-04-12 14:16:35 · 697 阅读 · 0 评论 -
uva437
he 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原创 2016-11-24 00:00:37 · 1116 阅读 · 0 评论 -
uva1025 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 tim原创 2016-11-23 23:50:56 · 978 阅读 · 0 评论 -
状态压缩DP----车的摆放4
题目描述在n*m(n,m≤80并且m*n≤80)的方格棋盘上放置k(k不大于20)个车(这是一种特殊的车,它只能攻击相邻8个位置的车),求使它们不能互相攻击的方案总数。输入输入有多个样例,每个样例有三个整数,n,m,k。输出输出所有可能的方案总数,由于结果很大,你只需要输出mod 200640345的余数就行了。样例输入1 5 12 2 12原创 2016-10-24 23:39:26 · 1200 阅读 · 0 评论 -
TYVJ 1098 任务安排
题目描述N个任务排成一个序列在一台机器上等待完成(顺序不得改变),这N个任务被分成若干批,每批包含相邻的若干任务。从时刻0开始,这些任务被分批加工,第i个任务单独完成所需的时间是Ti。在每批任务开始前,机器需要启动时间S,而完成这批任务所需的时间是各个任务需要时间的总和(同一批任务将在同一时刻完成)。每个任务的费用是它的完成时刻乘以一个费用系数Fi。请确定一个分组方案,使得总费用最小。 例原创 2016-10-24 23:38:16 · 1521 阅读 · 0 评论 -
分解式的个数
题目描述大于1的正整数可以分解成一组因子的乘积,例如12可以分解成:12、6*2、4*3、3*4、3*2*2、2*6、2*3*2、2*2*3,共8个分解式。请设计算法,计算指定的大于1的正整数的分解式的个数。输入第一行为测试用例个数n,n≤100000。 从第二行开始,共有n行,每行为一个大于1的正整数m,m≤10001。输出对每个测试用例m,输出其分解式的原创 2016-10-24 23:37:09 · 2167 阅读 · 0 评论 -
数字三角形
题目描述给出一个数字三角形(形式如图1所示),从该三角形最上一层开始走,每一步只能往下一层走,并且只能斜向左下或斜向右下走,直到走到最下层时结束,如何才能使经过路径上的数字之和最大?12 153 13 144 12 11 105 6 7 8 9输入多组测试数据。对于每组数据,第一行输入一个N(1 输出一个整数,原创 2016-10-24 23:34:41 · 1181 阅读 · 0 评论 -
TYVJ 1050 最长公共子序列
题目描述一个字符串A的子串被定义成从A中顺次选出若干个字符构成的串。如A=“cdaad" ,顺次选1,3,5个字符就构成子串" cad" ,现给定两个字符串,求它们的最长共公子串。输入第一行两个字符串用空格分开。输出最长子串的长度。样例输入abccd aecd样例输出3提示两个串的长度均小于2000原创 2016-10-24 23:33:38 · 1167 阅读 · 0 评论 -
TYVJ 1049 最长不下降子序列
题目描述求最长不下降子序列的长度输入第一行为n,表示n个数 第二行n个数输出最长不下降子序列的长度样例输入31 2 3样例输出3#include#include#include#include#includeusing namespace std;int a[50005];int d[5000原创 2016-10-24 23:32:40 · 1126 阅读 · 0 评论 -
TYVJ 1073 加分二叉树
问题 C TYVJ 1073 加分二叉树时间限制: 0 Sec 内存限制: 128 MB[提交]题目描述设一个n个节点的二叉树tree的中序遍历为(l,2,3,…,n),其中数字1,2,3,…,n为节点编号。每个节点都有一个分数(均为正整数),记第j个节点的分数为di,tree及它的每个子树都有一个加分,任一棵子树subtree(也包含tree本身)的加分计算方法如下:原创 2016-09-25 22:52:54 · 1346 阅读 · 0 评论 -
poj1276
Cash MachineTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 32757 Accepted: 11867DescriptionA Bank plans to install a machine for cash withdrawal. The转载 2016-08-06 15:36:03 · 920 阅读 · 0 评论 -
UVA 1626 Brackets sequence
DescriptionLet 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 an原创 2016-11-29 11:27:47 · 1003 阅读 · 0 评论 -
UVA 1331 Minimax Triangulation
话说这个题我开始是不会滴,第一次看了人家的代码照着写的。有机会的话更新一下,写一下自己的代码。最优三角剖分的一类题目都是差不多的。给你一个多边形,让你把它分割成若干个三角形,求三角形某最优解,比如UVA1331要求面积最大的三角形的面积最小。如图是各种切割方法: 不知道一开始看到最大值最小化会不会又一下子想到枚举答案二分去了呢,不过本题正解是DP原创 2016-11-29 11:31:40 · 1102 阅读 · 0 评论 -
poj2486 apple tree
Wshxzt is a lovely girl. She likes apple very much. One day HX takes her to an apple tree. There are N nodes in the tree. Each node has an amount of apples. Wshxzt starts her happy trip at one node. S转载 2016-12-06 10:19:42 · 986 阅读 · 0 评论 -
poj 3071 football
Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, …, 2n. In each round of the tournament, all teams still in the tournament are placed in a list in order of increasin原创 2016-12-06 10:15:20 · 988 阅读 · 0 评论 -
最优三角剖分
问题:对于一个n个顶点的凸多边形,有很多种方法对它进行三角剖分,n-3条互不相交的边把它分成n-2个三角形,让三角形的权和最大。输入:第一行输入n,表示n个顶点 后面的n行输入每行包括三个数,I,j,k; 分别为两个顶点的编号以及两点之间线的长度;输出:剖分三角形最大权和思路:使用一个n*n的矩阵存储两条边的信息;使用一个n*n的矩阵存储最大权和t[原创 2016-11-22 12:47:17 · 1339 阅读 · 0 评论 -
最长公共子序列
问题描述:字符序列的子序列是指从给定字符序列随意的(不一定是连续的)去掉若干个字符(也可能一个也去不掉)后形成的字符序列。求给定的两个字符串的最长公共子序列输入:输入两行字符串输出:输出最长公共子序列的个数分析:若在序列A,B中查找最长公共子序列,i,j分别为字符串的下标,则分为三种情况1:边界情况,当i==0,j==0时最长子序列为0;2:当a[i]==b[j原创 2016-11-22 12:09:00 · 1009 阅读 · 0 评论 -
四柱汉诺塔
问题;有a,b,c,d四根柱子,要求最小的步数求出把a上的n根汉诺塔移到d上解法:1. 先把a上的的n个盘子分成两部分:(n-k)和k个,上层为k个2. 把a上层的k个用四柱汉诺塔的方法借助c,d移动到b上3. 把a剩下的n-k个盘用三柱汉诺塔的方法经过c移动到d上4. 把b上的k个汉诺塔借助四柱汉诺塔的方式经过a,c移动到d上由此可见要算n个盘子的四柱汉诺塔的步数等于原创 2016-11-22 12:07:02 · 1863 阅读 · 0 评论 -
uva10003 Cutting Sticks
Cutting Sticks You have to cut a wood stick into pieces. The most affordable company, The Analog Cutting Machinery, Inc. (ACM), charges money according to the length of the stick being cut原创 2016-11-29 11:21:40 · 1033 阅读 · 0 评论 -
UVA 1220 Party at Hali-Bula
题目大意:n 个人形成一个关系树,每个节点代表一个人,节点的根表示这个人的唯一的直接上司,只有根没有上司。要求选取一部分人出来,使得每 2 个人之间不能有直接的上下级的关系,求最多能选多少个人出来,并且求出获得最大人数的选人方案是否唯一。解题思路:分析发现是要求一个树的最大独立集。这里可以用树形 DP 解决。定义dp【x】【0】:表示在 i 点不选 i 点的以 x 为子树的最大原创 2016-11-30 21:28:53 · 1070 阅读 · 0 评论 -
UVA 12186 Another Crisis
Description Download as PDFA couple of years ago, a new world wide crisis started, leaving many people with economical problems. Some workers of a particular company are trying to ask for an inc原创 2016-11-30 21:25:52 · 973 阅读 · 0 评论 -
hdu6087 dp
类似于最长公共上升子序列,对于每个i,只考虑存在j使得a[i]==b[j]的情况。 dp[i][j][0]表示以a[i]和b[j]为公共序列结尾且为波谷的情况总和。 dp[i][j][1]则表示波峰的情况总和。 S[i][j][0]表示sum(dp[k][j][0] | 1S[i][j][1]则表示sum(dp[k][j][1] | 1那么对于每个a[i],只有存在j使得b[j转载 2017-08-04 21:18:08 · 1452 阅读 · 0 评论