Processing math: 0%

随笔分类 -  动态规划—基础dp

摘要:我太难了 阅读全文
posted @ 2020-04-07 16:52 天之道,利而不害 阅读(341) 评论(0) 推荐(0) 编辑
摘要:dp[i][j]: 表示从(0,0)走到(i,j)的方案数 $$ dp[i][j]=\begin{cases} dp[i][j] + dp[i 1][j 1] & (从左边过来) \\ dp[i][j] + dp[i 1][j + 1] & (从右边过来) \\ dp[i][j] + d 阅读全文
posted @ 2018-12-29 16:01 天之道,利而不害 阅读(290) 评论(0) 推荐(0) 编辑
摘要:题意 将一颗n(1 \leq n \leq 2000)个结点的树,分成t(1\leq t \leq n)个连通块,且每个连通块的大小都小于或者等于k(1 \leq k \leq 2000),求划分方案数? 题解 dp[i][j]:以i为根的子树向父亲结点u提供j个点的贡献 阅读全文
posted @ 2018-11-30 13:09 天之道,利而不害 阅读(261) 评论(0) 推荐(0) 编辑
摘要:题解 dp[i][j]:用了i个数序号是j的方案数。 dp[i][j] = \begin{cases} dp[i 1][j] + dp[i 1][j 1] & (a[i] \% j == 0)\\ dp[i 1][j] \\ \end{cases} 因为dp[i][j]阅读全文
posted @ 2018-11-30 00:13 天之道,利而不害 阅读(388) 评论(0) 推荐(0) 编辑
摘要:题意 有一个长度为n(n\le1e^9)只由阿拉伯数字组成的串A,现在给一个长度为m(m\le20)同样只由阿拉伯数字组成的串B,求满足条件的A串个数,条件:B串不包含在A串。 题解 dp[i][j]=长度为i且末尾(后缀)已经与B串首部(前缀)匹配了 阅读全文
posted @ 2018-09-30 13:55 天之道,利而不害 阅读(718) 评论(0) 推荐(1) 编辑
摘要:题解:dp[ i ][ k ][0 ~ 3] :表示第 i 列状态为s(s = 0,1,2,3)时总的联通个数。 注意:dp[ i ][ k ][ 1 ] 和 dp[ i ][ k ][ 2 ] 的转移。 阅读全文
posted @ 2018-09-24 12:12 天之道,利而不害 阅读(221) 评论(0) 推荐(0) 编辑
摘要:ps:dp[ i ][ j ][ k ]:i 个数用掉了 j 行 k 列。有三种状态:第 i + 1 个数要在原来的基础上用掉新的 1 行,或者用掉新的 1 列, 或者填在原来行列的交点上(既不用掉新的一行也不用掉新的一列),还是太单纯了,竟然在找规律。。。。 阅读全文
posted @ 2018-08-21 12:36 天之道,利而不害 阅读(268) 评论(0) 推荐(0) 编辑
摘要:题解:dp[a[i]]=max(dp[a[i]-d]~dp[a[i]+d])。 感受:学会看数据啊,刚开始想的是贪心,发现可以不连续,看了数据,想了分块,线段树。。。最后发现可以dp。刚好一个小时 阅读全文
posted @ 2018-05-13 23:59 天之道,利而不害 阅读(308) 评论(0) 推荐(0) 编辑
摘要:Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to pl 阅读全文
posted @ 2017-10-27 23:45 天之道,利而不害 阅读(615) 评论(0) 推荐(0) 编辑
摘要:题意:求最大子矩阵的和 题解:一维的最大子段和扩展到二维(一直想着取矩阵的左上和右下两个顶点,然后压缩成一维,。。。真是傻)。在脑海中建立一个坐标系,然后把矩阵放 进去,它的子矩阵相当于沿着y轴方向的某个连续子段,只是这个子段的宽度需要枚举。然后令map[ i ][ j ]表示第 i 行 1~j 列 阅读全文
posted @ 2017-09-24 10:55 天之道,利而不害 阅读(478) 评论(0) 推荐(0) 编辑
摘要:题意:一个系统由n个设备组成,每个设备可以由mi个厂商提供,每个设备你可以选一个厂商,在你选定的厂商的设备中,b(带宽)是所选设备中b值最小的,类似于短板效应,p是所有价格之和,要求b/p最小。(看了很久才懂了题意,~~~要史了) 题解:dp[ i ][ j ]表示选了i个设备,带宽最小为j所用到的 阅读全文
posted @ 2017-09-22 11:56 天之道,利而不害 阅读(741) 评论(0) 推荐(0) 编辑
摘要:A string is called bad if it has 3 vowels in a row, or 5 consonants in a row, or both. A string is called good if it is not bad. You are given a strin 阅读全文
posted @ 2017-09-12 23:17 天之道,利而不害 阅读(236) 评论(0) 推荐(0) 编辑
摘要:A straight dirt road connects two fields on FJ's farm, but it changes elevation more than FJ would like. His cows do not mind climbing up or down a si 阅读全文
posted @ 2017-08-31 15:49 天之道,利而不害 阅读(131) 评论(0) 推荐(0) 编辑
摘要:Farmer John goes to Dollar Days at The Cow Store and discovers an unlimited number of tools on sale. During his first visit, the tools are selling var 阅读全文
posted @ 2017-08-30 16:56 天之道,利而不害 阅读(194) 评论(0) 推荐(0) 编辑
摘要:The people of Mohammadpur have decided to paint each of their houses red, green, or blue. They've also decided that no two neighboring houses will be 阅读全文
posted @ 2017-08-10 10:07 天之道,利而不害 阅读(271) 评论(0) 推荐(0) 编辑
摘要:Its year 2200, planet Earth is out of resources and people are relying on the resources from other planets. There are several Refining Companies who c 阅读全文
posted @ 2017-08-10 09:49 天之道,利而不害 阅读(198) 评论(0) 推荐(0) 编辑
摘要:Samir returned home from the contest and got angry after seeing his room dusty. Who likes to see a dusty room after a brain storming programming conte 阅读全文
posted @ 2017-08-08 17:25 天之道,利而不害 阅读(179) 评论(0) 推荐(0) 编辑
摘要:Yes, you are developing a 'Love calculator'. The software would be quite complex such that nobody could crack the exact behavior of the software. So, 阅读全文
posted @ 2017-08-08 14:50 天之道,利而不害 阅读(365) 评论(0) 推荐(0) 编辑
摘要:题意:你的任务是设计一个照明系统。一共有n(n<=1000)种灯泡选择,不同种类的灯泡必须有不同的电源,但同一种灯泡可以用同一种电源。 每种灯泡用四个数值表示:电压值V,电源费用K,每个灯泡的费用C,和所需灯泡的数量L。 题解:首先可以想到一个结论;每种电压的灯泡要么全换,要么全不换。因为如果只换部 阅读全文
posted @ 2017-08-07 16:23 天之道,利而不害 阅读(309) 评论(0) 推荐(0) 编辑
摘要:题解:dp[ i ][ j ]表示从格子(i,j)出发到最后一列的最小开销。 以前看这道题,感觉不太好写。其思路有点像数字三角行,从后往前推,不过这道题还要处理很多细节,一是初始化,二是方向的问题 ,因为图是环形的, 三是记录路径(长知识了)。 代码摘自紫书 阅读全文
posted @ 2017-08-07 15:37 天之道,利而不害 阅读(205) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示