
动态规划
coldfresh
那我们开始吧
展开
-
矩阵乘法(动态规划)
动态规划原创 2017-03-28 20:54:30 · 1736 阅读 · 0 评论 -
【51nod】AVL树的种类
平衡二叉树(AVL树),是指左右子树高度差至多为1的二叉树,并且该树的左右两个子树也均为AVL树。 现在问题来了,给定AVL树的节点个数n,求有多少种形态的AVL树恰好有n个节点。 Input 一行,包含一个整数n。 (0 < n <= 2000) Output 一行表示结果,由于结果巨大,输出它对1000000007取余数的结果。 Input示例 10 Output示例...原创 2018-08-16 15:36:03 · 434 阅读 · 0 评论 -
【wanaflyCamp】平衡二叉树(dp)
题目描述平衡二叉树,顾名思义就是一棵“平衡”的二叉树。在这道题中,“平衡”的定义为,对于树中任意一个节点,都满足左右子树的高度差不超过 . 空树的高度定义为0,单个节点的高度为1,其他情况下树的高度定义为根节点左右子树高度最大值 + 1。 一棵在高度上平衡的树,节点数可能不平衡。再定义一棵树的不平衡度为这棵树中所有节点的左右子树的节点数之差的最大值。 给定平衡的定义参数, 你需要求出所有高...原创 2018-08-07 17:26:32 · 698 阅读 · 0 评论 -
【wanaflyCamp】Growth(dp)
题目描述弱弱有两个属性a和b,这两个属性初始的时候均为0,每一天他可以通过努力,让a涨1点或b涨1点。 为了激励弱弱努力学习,我们共有n种奖励,第i种奖励有xi,yi,zi三种属性,若a ≥ xi且b ≥ yi,则弱弱在接下来的每一天都可以得到zi的分数。 问m天以后弱弱最多能得到多少分数。 输入第一行一个两个整数n和m(1 ≤ n ≤ 1000,1 ≤ m ≤ 2000000...原创 2018-08-06 16:25:48 · 358 阅读 · 0 评论 -
Seam Carving HDU - 5092(简单dp)
Fish likes to take photo with his friends. Several days ago, he found that some pictures of him were damaged. The trouble is that there are some seams across the pictures. So he tried to repair these ...原创 2018-07-16 19:18:27 · 385 阅读 · 0 评论 -
BUY LOW, BUY LOWER POJ - 1952(LIS)(dp)
The advice to “buy low” is half the formula to success in the bovine stock market.To be considered a great investor you must also follow this problems’ advice: “Buy low; buy lowe...原创 2018-04-29 16:24:37 · 173 阅读 · 0 评论 -
Problem Arrangement ZOJ - 3777 (状压dp)
The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem setter, Edward is going to arrange the order of the problems. As we know, the arrangement will have a great effect o...原创 2018-04-25 18:43:44 · 229 阅读 · 0 评论 -
Batch Scheduling POJ - 1180(斜率dp)
There is a sequence of N jobs to be processed on one machine. The jobs are numbered from 1 to N, so that the sequence is 1,2,…, N. The sequence of jobs must be partitioned into one or more batches, wh...原创 2018-04-22 17:35:15 · 276 阅读 · 0 评论 -
Naptime POJ - 2228(环形dp处理)
Goneril is a very sleep-deprived cow. Her day is partitioned into N (3 <= N <= 3,830) equal time periods but she can spend only B (2 <= B < N) not necessarily contiguous periods in bed. Du...原创 2018-03-28 20:00:19 · 431 阅读 · 0 评论 -
【51nod】猪和回文
一只猪走进了一个森林。很凑巧的是,这个森林的形状是长方形的,有n行,m列组成。我们把这个长方形的行从上到下标记为1到n,列从左到右标记为1到m。处于第r行第c列的格子用(r,c)表示。刚开始的时候猪站在(1,1),他的目标是走到(n,m)。由于猪回家心切,他在(r,c)的时候,只会往(r+1,c)或(r,c+1)走。他不能走出这个森林。这只猪所在的森林是一个非同寻常的森林。有一些格子看起来...原创 2018-08-16 18:28:10 · 238 阅读 · 0 评论 -
【HDU-5000】Clone(dp)
Problem Description After eating food from Chernobyl, DRD got a super power: he could clone himself right now! He used this power for several times. He found out that this power was not as perfect as...原创 2018-08-16 20:29:09 · 237 阅读 · 0 评论 -
【51nod 1353】 树(树形DP)
基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题今天小a在纸上研究树的形态,众所周知的,有芭蕉树,樟树,函树,平衡树,树套树等等。那么小a今天在研究的就是其中的平衡树啦。小a认为一棵平衡树的定义为一个n个点,从1到n编号,n-1条边,且任意两点间一定存在唯一一条简单路径,且n&amp;gt;=k。现在小a看到一棵很大很大的树,足足有n个节点,这里n一定大于等于k!为...原创 2018-10-19 16:33:54 · 352 阅读 · 0 评论 -
【51nod 1293】 球与切换器(dp、模拟)
题目来源: Codility基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题有N行M列的正方形盒子。每个盒子有三种状态0, -1, +1。球从盒子上边或左边进入盒子,从下边或右边离开盒子。规则:如果盒子的模式是-1,则进入它的球从下面出去。(方向变为向下)如果盒子的模式是+1,则进入它的球从右面出去。 (反向变为向右)如果盒子的模式是0, 则进入它的球方...原创 2018-10-15 21:54:36 · 257 阅读 · 0 评论 -
【51nod 1274】 最长递增路径 (dp)
**题目来源: Codility 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题** 一个无向图,可能有自环,有重边,每条边有一个边权。你可以从任何点出发,任何点结束,可以经过同一个点任意次。但是不能经过同一条边2次,并且你走过的路必须满足所有边的权值严格单调递增,求最长能经过多少条边。以此图为例,最长的路径是: 3 -> 1 -> 2 ...原创 2018-09-13 14:00:58 · 355 阅读 · 0 评论 -
【HDU - 5009 】Paint Pearls (dp)
Lee has a string of n pearls. In the beginning, all the pearls have no color. He plans to color the pearls to make it more fascinating. He drew his ideal pattern of the string on a paper and asks for ...原创 2018-09-07 14:03:13 · 242 阅读 · 0 评论 -
【51nod】环
基准时间限制:1 秒 空间限制:131072 KB 分值: 80 有一个有向图。这张图有n个点和m条有向边。 他很好奇不相交的环(简单环)来覆盖所有点的方案数(数字可能很大请模998,244,353)。 Input 第一行有n和m。(1<=n<=20,1<=m<=n*(n-1)) 后面m行描述着m条边。 输入保证没有重边自环。 Output 输出方案数。 ...原创 2018-09-03 19:44:23 · 268 阅读 · 0 评论 -
【51nod】调查任务(tarjan+dp)
基准时间限制:4 秒 空间限制:524288 KB 分值: 80 lbn是战忽中心——一个绝密的军事组织的一个军官,今天他接到了一个紧急任务:调查敌国X国某些城市的经济情况。 X国有N个城市,由M条单向道路连接,其中S城是X国的首都。 每个城市i有一个发达指数a[i],我们定义城市i的经济状况为首都S到城市i任意一条路径上两个不同的城市x,y的a[x] mod a[y]的最大值。(x和y必须...原创 2018-09-03 16:55:50 · 291 阅读 · 0 评论 -
【1052】 最大M子段和 (dp)
N个整数组成的序列a[1],a[2],a[3],…,a[n],将这N个数划分为互不相交的M个子段,并且这M个子段的和是最大的。如果M >= N个数中正数的个数,那么输出所有正数的和。 例如:-2 11 -4 13 -5 6 -2,分为2段,11 -4 13一段,6一段,和为26。 Input 第1行:2个数N和M,中间用空格分隔。N为整数的个数,M为划分为多少段。(2 <= N ...原创 2018-09-05 15:17:30 · 455 阅读 · 0 评论 -
【HRBUST - 1284 】编辑距离(简单dp)
俄罗斯科学家Vladimir Levenshtein在1965年提出了编辑距离概念。编辑距离,又称Levenshtein距离,是指两个字符串之间,由一个转成另一个所需的最少编辑操作次数。许可的三种编辑操作包括插入一个字符、删除一个字符、将一个字符替换成另一个字符。 至今,编辑距离一直在相似句子检索的领域中发挥着不可忽视的作用。我们不妨来设计一个程序,计算两个字符串的编辑距离。Input...原创 2018-08-23 15:18:27 · 341 阅读 · 0 评论 -
Cleaning Shifts POJ - 3171 (线段树优化dp)
Farmer John’s cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer John, the most obliging of farmers, has no choice but hire so...原创 2018-04-15 22:05:42 · 320 阅读 · 0 评论 -
Accumulation Degree POJ - 3585 (树形dp)(二次扫描和换根法)
Trees are an important component of the natural landscape because of their prevention of erosion and the provision of a specific ather-sheltered ecosystem in and under their foliage. Trees have also b...原创 2018-03-26 16:09:35 · 1622 阅读 · 0 评论 -
Hie with the Pie POJ - 3311(wa)
The Pizazz Pizzeria prides itself in delivering pizzas to its customers as fast as possible. Unfortunately, due to cutbacks, they can afford to hire only one driver to do the deliveries. He will wait f原创 2017-07-17 10:49:52 · 315 阅读 · 0 评论 -
炮兵阵地 POJ - 1185(状态压缩)
司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队。一个N*M的地图由N行M列组成,地图的每一格可能是山地(用”H” 表示),也可能是平原(用”P”表示),如下图。在每一格平原地形上最多可以布置一支炮兵部队(山地上不能够部署炮兵部队);一支炮兵部队在地图上的攻击范围如图中黑色区域所示: 如果在地图中的灰色所标识的平原上部署一支炮兵部队,则图中的黑色的网格表示它能够攻击到的区域:沿横向左右各两格原创 2017-07-16 15:25:06 · 503 阅读 · 0 评论 -
Corn Fields POJ - 3254(状态压缩dp入门)
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, s原创 2017-07-06 12:37:51 · 862 阅读 · 0 评论 -
合并石子(区间dp)
动态规划原创 2017-03-29 11:06:11 · 547 阅读 · 0 评论 -
You Are the One(区间dp)(fromHDU)
dp原创 2017-04-17 15:09:07 · 365 阅读 · 0 评论 -
男神的礼物(区间dp变式)
动态规划原创 2017-04-17 11:02:23 · 533 阅读 · 0 评论 -
最长回文(manacher算法)(fromHDU)
给出一个只由小写英文字符a,b,c…y,z组成的字符串S,求S中最长回文串的长度. 回文就是正反读都是一样的字符串,如aba, abba等 Input 输入有多组case,不超过120组,每组输入为一行小写英文字符a,b,c…y,z组成的字符串S 两组case之间由空行隔开(该空行不用处理) 字符串长度len <= 110000 Output 每一行一个整数x,对应一组case,原创 2017-04-15 11:22:32 · 375 阅读 · 0 评论 -
拿糖果(动态规划)
问题描述 妈妈给小B买了N块糖!但是她不允许小B直接吃掉。 假设当前有M块糖,小B每次可以拿P块糖,其中P是M的一个不大于根号下M的质因数。这时,妈妈就会在小B拿了P块糖以后再从糖堆里拿走P块糖。然后小B就可以接着拿糖。 现在小B希望知道最多可以拿多少糖。 输入格式 一个整数N 输出格式 最多可以拿多少糖 样例输入 15 样例输出 6 数据规模和约定原创 2017-03-29 14:46:25 · 1520 阅读 · 0 评论 -
Travelling HDU - 3001
After coding so many days,Mr Acmer wants to have a good rest.So travelling is the best choice!He has decided to visit n cities(he insists on seeing all the cities!And he does not mind which city being原创 2017-07-17 14:34:13 · 408 阅读 · 0 评论 -
Most Powerful ZOJ - 3471
Recently, researchers on Mars have discovered N powerful atoms. All of them are different. These atoms have some properties. When two of these atoms collide, one of them disappears and a lot of power i原创 2017-07-17 17:21:14 · 328 阅读 · 0 评论 -
最大的算式 蓝桥
问题描述 题目很简单,给出N个数字,不改变它们的相对位置,在中间加入K个乘号和N-K-1个加号,(括号随便加)使最终结果尽量大。因为乘号和加号一共就是N-1个了,所以恰好每两个相邻数字之间都有一个符号。例如: N=5,K=2,5个数字分别为1、2、3、4、5,可以加成: 1*2*(3+4+5)=24 1*(2+3)*(4+5)=45 (1*2+3)*(4+5)=45 ...原创 2018-03-25 16:07:22 · 481 阅读 · 0 评论 -
(pat)A1068. Find More Coins
Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However,...原创 2018-03-12 20:48:58 · 197 阅读 · 0 评论 -
Islands and Bridges POJ - 2288
题目链接:http://poj.org/problem?id=2288题意:仍然是求一条哈密顿回路,不过权值和的计算包括三部分:所经过的点权和,连续经过的两个点的权值乘积,连续三个点彼此可达则再加上三点乘积,问最大权值为多少,且有多少种方案达到该权值,注意一条路径的走法只能算一次评价:这题我一看就知道是状压dp,一般我能一眼看出来思路的都是水题,但是实现上出了很多问题,原来这题是会超int...原创 2018-03-03 19:39:07 · 243 阅读 · 0 评论 -
Mahmoud and a Message CodeForces - 766C (dp)
Mahmoud wrote a message s of length n. He wants to send it as a birthday present to his friend Moaz who likes strings. He wrote it on a magical paper but he was surprised because some characters disapp原创 2017-11-20 22:15:50 · 354 阅读 · 0 评论 -
方格取数(1) HDU - 1565(状压dp)
给你一个n*n的格子的棋盘,每个格子里面有一个非负数。 从中取出若干个数,使得任意的两个数所在的格子没有公共边,就是说所取的数所在的2个格子不能相邻,并且取出的数的和最大。 Input 包括多个测试实例,每个测试实例包括一个整数n 和n*n个非负数(n<=20) Output 对于每个测试实例,输出可能取得的最大的和 Sample Input 3 75 15 21 75 15原创 2017-11-08 21:47:36 · 394 阅读 · 0 评论 -
Two HDU - 5791 (DP)
Alice gets two sequences A and B. A easy problem comes. How many pair of sequence A’ and sequence B’ are same. For example, {1,2} and {1,2} are same. {1,2,4} and {1,4,2} are not same. A’ is a subsequen原创 2017-09-02 16:06:24 · 330 阅读 · 0 评论 -
Binary Apple Tree URAL - 1018 (树形dp)
Let’s imagine how apple tree looks in binary computer world. You’re right, it looks just like a binary tree, i.e. any biparous branch splits up to exactly two new branches. We will enumerate by integer原创 2017-07-26 14:50:17 · 335 阅读 · 0 评论 -
Mondriaan's Dream POJ - 2411(插头做法带更新)
Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his ‘toilet series’ (where he had to use his toilet paper to draw on, for all of hi原创 2017-07-17 21:47:49 · 308 阅读 · 0 评论 -
【CodeForces - 1149B】Three Religions(dp查询)
题目链接题目大意是给三个栈相当于,q个操作,一种是指定加在某个队列一个字符,第二种是删掉某个栈的一个字符。然后每次操作完问是否满足下列情况:The three religions can coexist in peace if their descriptions form disjoint subsequences of the Word of Universe. More formally...原创 2019-05-04 20:32:17 · 353 阅读 · 0 评论