1 2 3 4

随笔分类 -  普通 动态规划

摘要:题目链接 本来有负边的最短路应该是O(n^3) 这个算法把负权图改成了正权图,可以跑dij,能够用来优化多次涉及spfa的算法,比如费用流 十分神奇 核心想法: 1.建立0 >(1--n),然后跑个spfa,得到d[i--n], 2.把x >y len改成 x >y len - d[y] + d[x 阅读全文
posted @ 2020-12-04 15:51 Lesning 阅读(84) 评论(0) 推荐(0)
摘要:https://www.luogu.com.cn/problem/CF1249F 这题看题解云里雾里的,我自认为我写的比较简单; dp[x][i]表示以x为根,选中节点离x最近距离为i。(最小深度) 那么如何转移呢? 答案无非就是两种方式构成的,原来子树上就有,两棵树合并而成。于是就有了下面的式子 阅读全文
posted @ 2020-10-24 10:08 Lesning 阅读(170) 评论(0) 推荐(0)
摘要:https://leetcode-cn.com/problems/count-all-possible-routes/ dp[x][y]从x到终点,使用y的油。 具体看注释 #include<iostream> #include<algorithm> #include<cstring> #inclu 阅读全文
posted @ 2020-09-08 19:29 Lesning 阅读(230) 评论(0) 推荐(0)
摘要:https://ac.nowcoder.com/acm/problem/20265 dp[a][b][c][d][e][llast]可以涂满1个块的颜色有a个,2个块的有b个。。。。。当前末尾是可以涂last个颜色的块涂的。 可以发现,如果用了一次b,b就会少一个颜色,a会增加一个颜色。原理就是这样 阅读全文
posted @ 2020-07-21 13:35 Lesning 阅读(268) 评论(0) 推荐(0)
摘要:如下图 #include<iostream> #include<cstring> #include<algorithm> #include<cstdio> using namespace std; int dp[1010][1010]; char list[1010]; char ans[1010] 阅读全文
posted @ 2020-04-04 18:11 Lesning 阅读(106) 评论(0) 推荐(0)
摘要:https://www.luogu.com.cn/problem/P1772 这是一个非常神奇的动态规划+最短路问题 #include<iostream> #include<cstring> #include<queue> #include<vector> using namespace std; 阅读全文
posted @ 2020-03-14 20:10 Lesning 阅读(92) 评论(0) 推荐(0)
摘要:这题比较特殊,石头按照环形放置 首位相接把数组复制两次就好了 最后枚举一下就行 #include<cstring> #include<iostream> #include<cstdio> using namespace std; typedef long long ll; const int max 阅读全文
posted @ 2020-02-25 00:05 Lesning 阅读(107) 评论(0) 推荐(0)
摘要:牛客的题 有一种情况,就是k小于n时候,1到不了k,那就把dp全设置成负无穷(-1不行)这样就用不到了 #include<iostream> #include<cstring> #include<queue> #include<algorithm> #include<cstdio> using na 阅读全文
posted @ 2020-02-10 00:27 Lesning 阅读(459) 评论(0) 推荐(0)
摘要:dp可真难呀 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> using namespace std; int map[220][220]; int list[1100]; int dp[1100][ 阅读全文
posted @ 2019-12-04 20:35 Lesning 阅读(176) 评论(0) 推荐(0)