摘要://每天整理一点,太多了 https://www.cnblogs.com/TheRoadToTheGold/p/6254255.html#4175712(ORZ) POJ 3468 板子题 注意下数据范围 (因为int会爆,以后一定好好看题,浪费我10min....) http://poj.org/
阅读全文
摘要:注意几个小细节就好了 1.空树也是树 2.不能有指向自身节点的边 3.节点入度必须有一个为0,其他都为1(避免环的存在) 代码就很简单了,水题,反正俺是个只会水题的垃圾
阅读全文
摘要:博文:https://blog.csdn.net/yjr3426619/article/details/82315133 带全并查集 路径压缩,表达每个当前node与 当前node所在的并查集的root 之间的关系 并查集一定是单向连通的,所以一些node处理时 【node1,node2】 weig
阅读全文
摘要://最近在跟着kuangbin大佬疯狂水题 (ORZ)
阅读全文
摘要://没什么好讲,被卡stringstream了,少用
阅读全文
摘要:按位非运算符是~,作用是将每位二进制取反 十进制2的二进制表示为: 0000,0010 每位都取反: 1111,1101 这是内存中的保存形式。 我们读取的十进制是根据原码来读取,而在内存中,数值都是以二进制补码形式保存的。 正数的补码和原码一样,负数的原码转补码或者补码转原码的规则:符号位不变,将
阅读全文
摘要:物品在容量足够的情况下可以一直取 但逆序时 就无法重复选择了
阅读全文
摘要:(important) 树中root到每一个node都存在唯一路径, // dfs(root) dis[node]求出root到node节点的距离 //so len(u,v) = dis[u] + dis[v] - 2dis[LCA(u,v)]; //LCA比较简单不谈,但初始化要放在函数外,很奇怪
阅读全文
摘要://简单题,但输入好像挺恶心的,反正俺是个只会做水题的垃圾#include//LCA问题(最小公共祖先节点) #include//Tarjan算法变形 #include #include #include #include #include using namespace std; const int maxn = 1000 + 15; int n,m; vector Grape[maxn];/...
阅读全文
摘要://Tarjan算法求LCS(树中的最小公共祖先节点)(离线) //if node 被标记过,说明节点已经被探索过,所以节点路径已经形成 //先把子树的query解决,只有把子树的儿子节点访问完毕才回溯并查集 #include #include #include #include using namespace std; const int maxn = 1e4 +15; vector Grap...
阅读全文
摘要://Tarjan算法(将强连通分量缩度再进行处理) //POJ 2186 #include #include #include #include #include #include using namespace std; const int maxn = 1e4 + 15; vector Grape[maxn]; int cnt;//缩度的节点个数 int arr[maxn];//缩点的标号...
阅读全文
摘要:#include<iostream> #include<cstdio> #include<string> #include<map> #include<cstring> #define inf (0x3f3f3f3f) using namespace std; const int maxn = 150 + 15; int Grape[maxn][maxn]; map<string,int> m;
阅读全文
摘要:// 母函数解决的问题 // n 种物品,每个有一个wi,组合成total价值有多少种组合方案 // 将组合问题转换为 幂级数上的相乘问题(important) (Orz) // #include<iostream> // #include<cstdio> // #include<cstring> // using namespace std; // int n,a[105],b[105],m,s
阅读全文
摘要://关于最长公共子串的一些简单想法 // if 求 str1 与 str2 的最长公共子串,可以将str1 每个字符与str2 每个字符建立矩阵 Grape[len1][len2] // 遍历 如果 str1[i]==str2[j] 则Grape[i][j] = 1 // 因此最长的公共子串为Grape图中最长的1对角线长 // 因此优化下 // if // str1[i] != str2[j]
阅读全文
摘要://判断唯一MST的思想 //先用Prim算法求出最小生成树的值 //枚举MST体系外的每一条边,加入MST,必然形成一个环,判断u - v的 //权值边是否和u - v路径的最大权值边相等,如果相等,则存在不止一条MST #include<iostream>//Judge 是否为唯一MST #include<cstdio> #include<cstring> #include<algorithm
阅读全文
摘要:#include//POJ2349 #include #include #include #include #define inf (0x3f3f3f3f) #define DEF (1e-5) using namespace std; const int maxn = 500 + 5; /*一些最小生成树的新见解 (因为最小生成树是贪心构造, 每一条边都是体系内的最短距 离,所以也可以用来求构...
阅读全文
摘要://dijkstra算法 求单源最短路径(板子) O(n^2)还能优化,等会补充 #include//important (不能求带负权值的图) #include #include #define inf (0x3f3f3f3f) using namespace std; const int maxn = 100 + 15; int Grape[maxn][maxn];//u - v的路...
阅读全文
摘要:#include<iostream>//Prim算法的简单实现(最小生成树的最小生成路径) #include<cstdio> #include<cstring> #define inf (0x3f3f3f3f) using namespace std; const int maxn = 100 +
阅读全文
摘要://刚开始傻乎乎的拿字典树写,佛了,就一水题
阅读全文
摘要:#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int maxn = 100 + 15; int n,m,t;//图中有n个节点 int topo[maxn];//储存拓扑排序的顺序 i
阅读全文
摘要://POJ 1018(DP) 当有俩个变量时可固定一个边量再去求另一个变量(important) #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #define inf (0x3f3f3f3f) using namespace std; int dp[115][1200];//前i个的设备的j带宽的
阅读全文
摘要:看了大佬的博客才搞懂...... 以每个小岛为坐标原点,建立圆,获得与x 轴的左交点 left 与右交点 right,获得了雷达在x轴上可以存在的区间,然后贪心枚举,具体看代码注释
阅读全文
摘要:一道简单DP,但我好像没用滚动数组,菜得真实 思路:i 从字符串尾n开始,j 从i开始,截取字符串 if(str[i] == str[j])因为字符相等,显然 dp[i][j] = dp[i+1][j-1] 当字符不相等时dp[i][j] = 1 + min(dp[i+1][j],dp[i][j-1
阅读全文
摘要:试了一下深搜每个节点结果TLE了 突然发现是个很明显的DP 从最小的节点开始,更新它四周的节点,如果存在比它高度高的节点,高的节点步数 + 1,因为节点的更新状态肯定是比它高度低那获取的,因此更新时四周比它低的节点已经确定了是最大步数了
阅读全文
摘要:#include<iostream>//深搜学习(经典) #include<cstdio>//深搜可以作为面临多种选择时的不断尝试 #include<algorithm> #include<cstring> using namespace std; const int maxn = 105; int
阅读全文
摘要://多叉树的建立 #include<iostream> #include<cstdio> #include<string> #include<list> #include<map> #include<cstring> using namespace std; struct node { string name;//节点的名字 node* parent;//便于删除 list<node*> sons
阅读全文
摘要:C++容器内的next_permutation //适用于可重集
阅读全文