上一页 1 2 3 4 5 6 7 8 9 ··· 12 下一页

P1807 最长路

摘要: 链接:https://www.luogu.com.cn/problem/P1807 其实没什么难的,注意点:拓扑排序,把非1的入度为0的点及其衍生点全删了,不然会到一半无法拓扑下去。 关键在于我之前那个删点的操作,先看错误代码: ... void clearpoint(ll ix) { for (l 阅读全文
posted @ 2024-05-15 22:23 WHUStar 阅读(2) 评论(0) 推荐(0) 编辑

P3366 【模板】最小生成树

摘要: 链接:https://www.luogu.com.cn/problem/P3366 模板题: kruskal代码: 核心是对边的排序,遍历,选择。 #include<iostream> #include<vector> #include<algorithm> #include<math.h> #in 阅读全文
posted @ 2024-05-15 21:42 WHUStar 阅读(2) 评论(0) 推荐(0) 编辑

P1140 相似基因

摘要: 链接:https://www.luogu.com.cn/problem/P1140 题目: 思路:设置递推状态:dp[i][j]表示a的前i个碱基和b的前j个碱基配对的最大值。 那么递推: 1.ans1设置为dp[i-1][j-1]+val[a[i]][b[j]]就是说a[i]和b[j]可以凑一对, 阅读全文
posted @ 2024-05-15 16:25 WHUStar 阅读(1) 评论(0) 推荐(0) 编辑

P1122 最大子树和

摘要: 思路:由于是一棵n节点,n-1边的图,所以必然没有环,那么从任何一个节点出发都必然达到另外一个节点。 如果子节点的dp大于0,那么父节点加上,否则砍掉(不加) 同时如果visit过了那就不用visit,总体复杂度为O(n)。 代码: #include<iostream> #include<vecto 阅读全文
posted @ 2024-05-15 14:55 WHUStar 阅读(2) 评论(0) 推荐(0) 编辑

P1044 [NOIP2003 普及组] 栈

摘要: 链接:https://www.luogu.com.cn/problem/P1044 两种很好的思路: 代码: #include<iostream> #include<vector> #include<algorithm> #include<math.h> #include<sstream> #inc 阅读全文
posted @ 2024-05-15 13:47 WHUStar 阅读(2) 评论(0) 推荐(0) 编辑

P1347 排序

摘要: 链接:https://www.luogu.com.cn/problem/P1347 题目: 由于数据量很小,所以可以在线处理数据。 首先判断有没有环(这里不一定可以根据拓扑排序写出来,因为有的环可以只有部分节点,所以必须遍历所有节点的路径,判断有没有环); 然后查看入度为0的点,如果没有环而且入度为 阅读全文
posted @ 2024-05-14 10:18 WHUStar 阅读(10) 评论(0) 推荐(0) 编辑

希冀作业

摘要: #include<iostream> #include<vector> #include<algorithm> #include<math.h> #include<sstream> #include<string> #include<string.h> #include<iomanip> #incl 阅读全文
posted @ 2024-05-12 15:38 WHUStar 阅读(8) 评论(0) 推荐(0) 编辑

P2853 [USACO06DEC] Cow Picnic S

摘要: 简单的一道深搜: 思路:让每个有奶牛的农场沿着道路跑下去,跑到的农场加上root地方的奶牛数量,最后统计能有k头奶牛的农场数量就是答案 代码: #include<iostream> #include<vector> #include<algorithm> #include<math.h> #incl 阅读全文
posted @ 2024-05-11 21:43 WHUStar 阅读(4) 评论(0) 推荐(0) 编辑

P4017 最大食物链计数

摘要: 拓扑排序,有向图 记录每个点的入度,进行拓扑排序 然后怎么计算ans? 通过每个点的入度传递到子节点,在食物链的末尾加上即可,注意求余。 原理: 代码: #include<iostream> #include<vector> #include<algorithm> #include<math.h> 阅读全文
posted @ 2024-05-11 17:07 WHUStar 阅读(4) 评论(0) 推荐(0) 编辑

P4782 【模板】2-SAT

摘要: 简记: 1.参考学习: https://blog.csdn.net/qaqwqaqwq/article/details/126124806 https://www.cnblogs.com/cjjsb/p/9771868.html 2.代码: #include<iostream> #include<v 阅读全文
posted @ 2024-05-11 14:49 WHUStar 阅读(4) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 12 下一页