![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法方面
记录算法研究的点点滴滴。
重剑DS
学的越多,越觉无知
展开
-
P6192 【模板】最小斯坦纳树——最小斯坦纳树
根据题意,设 dp[i][s] 表示以 i 为根的一棵树,包含题目中所要求的集合 S 中所有点的最小代价。 给出一个例子,大体的算法流程图如下所示: 大佬的解析 代码如下: #include <iostream> #include <queue> #include <cstring> #include <climits> #include <algorithm> using namespace std; const int maxn = 11.原创 2021-12-26 22:46:55 · 949 阅读 · 0 评论 -
打印集合中所有子集的代码
#include <iostream> using namespace std; void print_subset(int n) { for(int i = 0; i < (1<<n); i++) { //i:0~2^n,每个i的二进制数对应一个子集,一次打印一个子集,最后得到所有子集 for(int j = 0; j < n; j++) { //打印一个子集,即打印i的二进制数中所有的1 if (i & (1<<j)) { /.原创 2021-05-16 21:39:54 · 279 阅读 · 0 评论 -
P3383 【模板】线性筛素数 —— 欧拉筛(线性筛) || 埃氏筛法 (素数筛模板)
解题代码 #include <iostream> #include <cstring> using namespace std; typedef long long ll; const int maxn = 100000010; ll n, q; int prime[maxn / 10]; //存储素数(从下标1开始,并且素数大小是升序的) bool isprime[maxn + 1]; //欧拉筛 void Prime() { memset(is...原创 2020-12-21 11:13:58 · 228 阅读 · 0 评论 -
F - Goldbach`s Conjecture(埃氏筛法 及 欧拉筛(线性筛))解题
AC代码如下 #include <iostream> #include <cstring> #include <unordered_map> using namespace std; typedef long long ll; const int maxn = (int)1e7; //这里挺坑的,需要开 maxn / 10 的数组才行,开maxn的话会Runtime Error int prime[maxn / 10...原创 2020-11-15 10:13:17 · 165 阅读 · 0 评论