随笔分类 -  acw基础

摘要:裴蜀定理 对于任意正整数a,b,一定存在一组正整数x和y,使得xa + yb = (a, b),并且(a, b)是a和b能凑(系数>0)出来的最小正整数。 为什么是最小? 因为a和b的最大公约数是(a, b),所以xa + yb = k(a, b)必定成立,又因为k是整数, a, b, x, y > 阅读全文
posted @ 2020-09-21 18:38 yys_c 阅读(167) 评论(0) 推荐(0)
摘要:注意:f(i, j)这个集合表示所有从0走到j的所有走法中走过i(二进制表示)中点的所有走法的集合,其中最后一步走到了j。一定要注意i仅仅表示走过了哪些点,而不代表走的顺序(可以是任何的合法顺序)。 #include<iostream> #include<cstring> using namespa 阅读全文
posted @ 2020-09-18 19:12 yys_c 阅读(117) 评论(0) 推荐(0)
摘要:#include<iostream> #include<cstring> using namespace std; const int N = 6010; int h[N], e[N], ne[N], idx; int w[N]; int n; int f[N][2]; int st[N]; voi 阅读全文
posted @ 2020-09-17 18:50 yys_c 阅读(83) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; const int N = 1010; char a[N], b[N]; int n, m; int f[N][N]; int main(){ scanf("%d%s%d%s", &n, a + 1, &m, b + 1 阅读全文
posted @ 2020-09-17 16:25 yys_c 阅读(105) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; const int N = 1010; char a[N], b[N]; int n, m; int f[N][N]; int main(){ cin >> n >> m; scanf("%s%s", a + 1, b 阅读全文
posted @ 2020-09-17 16:22 yys_c 阅读(107) 评论(0) 推荐(0)
摘要:思想:贪心+二分$O(nlogn)$ 末尾小的lis比末尾大的lis更优,因为他有希望去更新出更长的最长上升子序列 b[i]表示长度为i的最长上升子序列中末尾元素的最小值,b[i]单调增(用二分的条件,这个东西要证明) #include<iostream> using namespace std; 阅读全文
posted @ 2020-09-16 20:17 yys_c 阅读(187) 评论(0) 推荐(0)
摘要:状态转移方程: \(f(i, j) = min\{s[j] - s[l - 1] + f[i][k] + f[k + 1][j]\} (k = i, i + 1, ..., r - 1)\) 第一种(循环区间长度和左端点) #include<iostream> using namespace std 阅读全文
posted @ 2020-09-11 15:50 yys_c 阅读(149) 评论(0) 推荐(0)
摘要:#include<iostream> using namespace std; const int N = 310; int r, c; int g[N][N]; int f[N][N]; int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; int che 阅读全文
posted @ 2020-09-08 21:32 yys_c 阅读(91) 评论(0) 推荐(0)
摘要:简单版 区间查询 单点修改 树状数组其实就是想了一种办法,用一个新的数组来维护原数组的所有信息,其中这个新数组的单点查询和区间修改都是logn级别的(而原数组的单点查询O(1), 区间修改O(n)) A[1~8]对应的树状数组C[1~8]的构成如图 c[1] = a[1] c[2] = c[1] + 阅读全文
posted @ 2020-09-08 19:20 yys_c 阅读(190) 评论(0) 推荐(0)
摘要:完全背包解法: 为什么想到完全背包变式? 因为划分一个整数n,只能用<= n的数字,并且一个数字可以用无限次,所以是类似于完全背包的问题。 得到状态转移方程: \(f(i, j) = f(i - 1, j) + f(i - 1, j - i) + f(i - 1, j - 2 * i) + ... 阅读全文
posted @ 2020-09-07 10:13 yys_c 阅读(169) 评论(0) 推荐(0)
摘要:经典dp问题 自上向下dp #include<iostream> #include<cstring> using namespace std; const int N = 510, INF = 0x3f3f3f3f; int f[N][N], a[N][N]; int n; int main(){ 阅读全文
posted @ 2020-09-06 20:14 yys_c 阅读(143) 评论(0) 推荐(0)
摘要:不设置st出现无限递归的原因: 对于一个x号男生来说,找他的邻接点j,若j已经心有所属,那么会find(match[j]), 会让编号为match[j]的男生重新去找,那么这个男生开始找,如果在他已经匹配到的女生之前没有找到空闲的女生, 或者无法通过find()换一个另外的女生,那么这个男生找到的仍 阅读全文
posted @ 2020-09-06 18:20 yys_c 阅读(127) 评论(0) 推荐(0)
摘要:prim最小生成树:维护集合外所有点到集合的最小距离,每次找集合外的离集合最近的点k,并用k点更新集合到集合外所有点的距离最小值 #include<iostream> #include<cstring> using namespace std; const int N = 510, INF = 0x 阅读全文
posted @ 2020-08-31 16:21 yys_c 阅读(148) 评论(0) 推荐(0)
摘要:模拟一个小根堆,最重要的部分是heap_swap部分 heap_node和node_heap分别维护堆中的第a个元素是第几个插入的元素,和第k个插入的元素在堆中的位置 #include<iostream> using namespace std; const int N = 100010; int 阅读全文
posted @ 2020-08-31 15:47 yys_c 阅读(190) 评论(0) 推荐(0)
摘要:dijkstra算法的堆优化版本,把找dist数组中的最小值的复杂度优化为O(1). #include<iostream> #include<cstring> using namespace std; const int N = 150010; int heap[N], heap_node[N], 阅读全文
posted @ 2020-08-31 12:10 yys_c 阅读(111) 评论(0) 推荐(0)
摘要:循环n次,每次用离源点最近的点去更新源点到其他点的距离。 #include<iostream> #include<cstring> using namespace std; const int N = 510; int dist[N]; int d[N][N]; int st[N]; int n, 阅读全文
posted @ 2020-08-30 18:35 yys_c 阅读(84) 评论(0) 推荐(0)
摘要:按边权把边从小到大排序 用并查集加边 检查是否为连通图 #include<iostream> #include<algorithm> using namespace std; const int N = 100010, E = 200010; struct edge{ int a, b, w; bo 阅读全文
posted @ 2020-08-30 11:21 yys_c 阅读(121) 评论(0) 推荐(0)
摘要:本题练习离散化,二分找位置,数组去重。 #include<iostream> #include<algorithm> using namespace std; const int N = 100010; struct node{ int x, c; }nodes[N]; int n, m, k = 阅读全文
posted @ 2020-08-30 10:58 yys_c 阅读(99) 评论(0) 推荐(0)