02 2024 档案
摘要:开局宏定义: #include<bits/stdc++.h> #define int long long #define lson (now << 1)//现结点的左孩子 #define rson (now << 1 | 1)//右孩子 using namespace std; 结构体定义: str
阅读全文
摘要:合并类动态规划 合并:意思就是将两个或多个部分进行整合,当然也可以反过来,也就是是将一个问题进行分解成两个或多个部分。 特征:能将问题分解成为两两合并的形式 求解:对整个问题设最优值,枚举合并点,将问题分解成为左右两个部分,最后将左右两个部分的最优值进行合并得到原问题的最优值。有点类似分治算法的解题
阅读全文
摘要:线性动态规划: 不用多说,主要应用于求上升子序列,下降子序列等 直接看例题: 样例输入: 13 7 9 16 38 24 37 18 44 19 21 22 63 15 样例输出: max=8 7 9 16 18 19 21 22 63 解: #include<bits/stdc++.h> usin
阅读全文
摘要:一. 背包DP 1. 0/1背包: 要素: 每个物品只有选一次或不选两种选择 n个物品 ,每个物品只有一件,第i个物品体积为vi,价格pi,现在有一个体积为V的背包,选出若干件物品使背包里价值最大 装入第i件物品已用体积为j时,有两种选择: 1.不放入第i件物品:f[i][j]=f[i-1][j]
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; int main(){ int a, b; scanf("%d%d",&a, &b); int k = 0; while(k = a % b) { a = b; b = k; } printf("%d",b);
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; int b ,p ,k; //蒙哥马利取模运算 求 a^b mod c int Montgomery(int a, int b, int c){ int ans = 1; a = a % c; while(b
阅读全文
摘要:#include<bits/stdc++.h> using namespace std; const int N = 5e7+50; int n, tot, prime[N]; //prime存储所有素数 bool flag[N]; //判断是否为素数 int main(){ scanf("%d",
阅读全文