随笔分类 - 经典算法
1
摘要:eg1: Leecode class Solution { public: int maxHappyGroups(int batchSize, vector<int>& groups) { w = groups; n = w.size(); m = batchSize; ans = 0; for(i
阅读全文
摘要:csdn 定义f(N,M)表示一共N个人,编号为0 ~ N - 1,每次报数为M的人被踢出去,得到的最后的优胜者(只剩下一个人)的标号是多少 则有递推公式: code: //先把下标映射成0 ~ N - 1 int p = 0;
阅读全文
摘要:https://www.cnblogs.com/ljc20020730/p/9873457.html
阅读全文
摘要:这里的dist[i]是表示零号点到点i的距离,零号点是一个虚拟原点,到所有点的距离是零,没必要建立此点到其它点的边,只要模拟一边spfa的一次循环就行了
阅读全文
摘要:Kruskal算法既可以保证求出最小生成树,也可以保证最小生成森林,既可以保证全局最优,也可以在任一阶段保证最优,既可以保证求出的树的边权和最小,也可以保证添加的边权的最大值最小,且当枚举到某条边时,由于并查集的存在,会得到一系列边权小于当前值的最大连通块
阅读全文
摘要:DNA修复 看提交记录(有注释) #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 1010; int n, m; int
阅读全文
摘要:#include <iostream> using namespace std; const int N = 100010, MOD = 1e9 + 7; int n1, n2, m; // n1种普通币,n2种纪念币,凑成面值m int f[N]; // 背包问题:完全背包(普通币) + 0/1背
阅读全文
摘要:#include <iostream> #include <algorithm> #include <cstring> using namespace std; const int N = 1010; int a[N], b[N]; int n; int main() { while(cin >>
阅读全文
摘要:#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 100010; int n; int a[N], f[N], g[N];
阅读全文
摘要:#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; const int N = 10010; int n; struct Segment { int x,
阅读全文
摘要:####不修改val的值,只改变链表结构,时间复杂度O (nlgn), 额外空间O(lgn) class Solution { public: ListNode* getTail(ListNode *head){ while(head->next){ head = head->next; } ret
阅读全文
摘要:ACwing class Solution { public: vector<int> getMinimumValue(int n) { const int INF = ~(1 << 31); //自然是有符号数的最大值 int l = 0, r = n - 1; //二分边界 while(l <=
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; const int N = 1010; int n,m; int cnt; int mp[N][N]; int ans[N*N]; //mp 该点所属连通块的标号, ans表示该连通块的大小 char g[N
阅读全文
摘要:尼姆博弈:n堆物品,两人轮流取,每次从某堆中取最少一个,最后取完者胜 结论:将n堆物品全部异或后结果为0,则先手必败,否则必胜 威佐夫博弈:有两堆各若干个物品,两人轮流从任意一堆中取出至少一个或者同时从两堆中取同样多的物品,规定每次至少取一个,至多不限,最后取光者胜利 结论:(黄金分割比)首先求出差
阅读全文
摘要:#include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #include<cmath> #define x first #define y second using namespace std; const
阅读全文
摘要:[this is](TSP问题+例题 - 快乐的黄鳝 - 博客园 (cnblogs.com))
阅读全文
1