1 2 3 4

随笔分类 -  图论

摘要:树上启发式合并 枚举每个数字的所有因子,存起来 官方题解传送门 https://ac.nowcoder.com/discuss/485120?type=101&order=0&pos=2&page=1&channel=-1&source_id=1 题目传送门 https://ac.nowcoder. 阅读全文
posted @ 2020-08-24 23:10 Lesning 阅读(194) 评论(0) 推荐(0)
摘要:https://ac.nowcoder.com/acm/contest/6037/F 很诡异,对于8 3 2 1 1这种,答案是7(3+2+1+1), 对于6 5 4 3 2 1这种,是(6+5+4+3+2+1)/2 所以求出每种颜色的最大数量 还有颜色总数就能在O(1)算出来一棵树了。但是吧。。。 阅读全文
posted @ 2020-08-20 17:30 Lesning 阅读(151) 评论(0) 推荐(0)
摘要:神奇的树形DP+二分图最大权值匹配转移 dp[x][y]表示以左边的树x为根,右边的树y为根,他们有dp[x][y]个序号是重合的,若x和y不同构那就dp[x][y] = -INF; 如何转移? 给x的儿子们和y的儿子们建个二分图跑最大权值匹配,跑下来的最大权值就是儿子们的答案,很好笑,但是复杂度有 阅读全文
posted @ 2020-08-11 16:44 Lesning 阅读(326) 评论(0) 推荐(0)
摘要:本题和cf 888G是一样的 利用分治算法 #include<iostream> #include<cstring> #include<algorithm> #include<vector> using namespace std; const int maxn = 2e5+11; typedef 阅读全文
posted @ 2020-07-31 18:13 Lesning 阅读(172) 评论(0) 推荐(0)
摘要:https://ac.nowcoder.com/acm/problem/51265 割点的板子 #include<iostream> #include<cstring> #include<algorithm> #include<vector> #include<queue> using namesp 阅读全文
posted @ 2020-07-11 16:44 Lesning 阅读(136) 评论(0) 推荐(0)
摘要:传送门 : https://ac.nowcoder.com/acm/contest/1063/C 棋子两两冲突,放最多的棋子。 把冲突的棋子之间建条边,建好后发现选择的是最大独立集。 图中不可能有奇环,是二分图。 二分图的 最大独立集 = 顶点总数 - 最小路径覆盖 = 顶点总数 - 最大匹配 然后 阅读全文
posted @ 2020-07-10 17:06 Lesning 阅读(314) 评论(0) 推荐(0)
摘要:传送门 : http://poj.org/problem?id=2226 这个题需要的知识 1 二分图的最大匹配(网络流,或者匈牙利) 2 二分图的最小顶点覆盖等于最大匹配 左边顶点是行编号,右边顶点是列编号,每个边是一个泥坑。顶点覆盖边,就是木板覆盖泥坑。 具体看代码吧,横着扫一遍竖着再扫一遍 # 阅读全文
posted @ 2020-07-09 18:03 Lesning 阅读(209) 评论(0) 推荐(0)
摘要:妹想到会是二分图匹配问题 https://www.luogu.com.cn/problem/P1129 图片选自https://www.luogu.com.cn/blog/sswcdak/solution-p1129,一目了然 #include<iostream> #include<cstring> 阅读全文
posted @ 2020-07-09 11:06 Lesning 阅读(134) 评论(0) 推荐(0)
摘要:https://codeforc.es/contest/1364/problem/D 看错题了,要求小于等于k的环或者(k+1)/2个独立集 找环dfs树就行了,独立集不知道定理,就盲找了,前十几个数字总有在最大独立集中参与的吧...所以就和1相连的所有点都猜一猜。。。。 #include<iost 阅读全文
posted @ 2020-06-17 15:20 Lesning 阅读(171) 评论(0) 推荐(0)
摘要:https://ac.nowcoder.com/acm/contest/5902/C 感谢LDK大神提供的最后解法 一个点z 到另一个点集合S的最长路为 ans 集合S中的最远点对x,y ans = max(ans,dis(x,z),dis(y,z)); 就是这样了 #include<cstring 阅读全文
posted @ 2020-06-02 20:53 Lesning 阅读(203) 评论(0) 推荐(0)
摘要:https://ac.nowcoder.com/acm/contest/5556/A 代码今天晚上补完 #include<iostream> #include<cstring> #include<algorithm> #include<queue> #include<vector> using na 阅读全文
posted @ 2020-05-08 18:38 Lesning 阅读(157) 评论(0) 推荐(0)
摘要:https://ac.nowcoder.com/acm/problem/13611 其实把,把树分成k个连通块有几种分配方法= 从树上取下k-1条边有几种取法,排列组合就行了,,,,,, #include<iostream> #include<algorithm> using namespace s 阅读全文
posted @ 2020-04-12 18:12 Lesning 阅读(135) 评论(0) 推荐(0)
摘要:https://ac.nowcoder.com/acm/contest/5086/C 其实不难,让a堵在c到1的毕竟之路上就好了,需要注意,若是a和c同时到1号点就是no,同时到其他点就是yes。。。。坑了好久我的妈呀 代码公式含义:len a到c 1的必经路的长度,假设到x点 ans b到c加上c 阅读全文
posted @ 2020-04-07 21:56 Lesning 阅读(151) 评论(0) 推荐(0)
摘要:分层图,每个转弯定义为一个操作,所以建立一个上层全是x轴,下层全是y轴,两层之间连一条权值为1的边代表转弯的代价。。挺简单的其实 https://www.luogu.com.cn/problem/P3831 #include<iostream> #include<cstring> #include< 阅读全文
posted @ 2020-03-31 20:34 Lesning 阅读(137) 评论(0) 推荐(0)
摘要:这个差分约束真的想不到,说白了就是统计C和D https://www.luogu.com.cn/problem/P2474 哎不说了,建议看看原来的题解 #include<iostream> #include<cstring> #include<algorithm> #include<cstdio> 阅读全文
posted @ 2020-03-21 18:24 Lesning 阅读(160) 评论(0) 推荐(0)
摘要:2-SAT快忘了,回忆了一下 x >y 代表选择x必选择y #include<iostream> #include<algorithm> #include<cstring> #include<stack> #include<cstdio> using namespace std; const int 阅读全文
posted @ 2020-03-19 18:48 Lesning 阅读(114) 评论(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)
摘要:DUS on tree 难得都不会,会的都是板子,可悲,可悲 题意:略 先想一个O(n^2)的写法,然后想办法去掉重复计算。究竟哪里重复 了呢? 假设p是x的儿子,p有很多个。每次计算答案的时候,如果“重儿子”(子孙最多的p)的答案可以直接用的话, 就可以省去很多的重复计算,这就是书上启发式合并 D 阅读全文
posted @ 2020-02-01 20:14 Lesning 阅读(168) 评论(0) 推荐(0)
摘要:很妙的一个树形DP问题,简单考虑了一下就过了 https://ac.nowcoder.com/acm/contest/2927/E 主要就是推公式(公式有点长呀) 大概就是这样,其实挺简单的。 #include<iostream> #include<cstring> #include<algorit 阅读全文
posted @ 2020-01-01 14:38 Lesning 阅读(178) 评论(0) 推荐(0)
摘要:有些题还得练练模拟的能力呀 这题一言难尽,他给的 图不是半连通子图呀,我崩溃了 要分好组,然后1给2连,2给3连,。。。。。n给1连。。 具体看代码,我写的比较捞了吧。。 #include<iostream> #include<cstring> #include<vector> #include<a 阅读全文
posted @ 2019-12-31 19:45 Lesning 阅读(154) 评论(0) 推荐(0)