随笔分类 - 算法
摘要:求每个数的最大质数用埃氏筛法,时间复杂度 O(nlognlogn) void get_primes(int n) { for (int i = 2; i <= n; i ++) if (!st[i]) { maxp[i] = i; for (int j = i + i; j <= n; j += i
阅读全文
摘要:树形DP 一、在u的子树中,选择一个大小恰好为m的包含u点的连通块,最大的权值和(u,m<=2e3) 这样写虽然是三重循环但是时间复杂度是O(nm)的 void dfs(int u) { sz[u] = 0; for (int v : son[u]) { dfs(v); for (int i = 0
阅读全文
摘要:#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m; int w[N]; struct node { int l, r; LL sum, add; }tr[N * 4]; void pushup(
阅读全文
摘要:https://www.acwing.com/problem/content/299/ 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 const int N = 1e3 + 5, mod = 1e9 + 7; 5 6 int n, m;
阅读全文

浙公网安备 33010602011771号