01背包问题 #include <iostream> #include <algorithm> #include <cstring> using namespace std; const int N = 1010; int n, m; int v[N], w[N]; int f[N]; int g[N]; int…
原题单链接:https://rentry.org/2f76axt4 见到很有意思的问题 : 以往见过许多教材,对动态规划(DP)的引入属于“奉天承运,皇帝诏曰”式:不给出一点引入,见面即拿出一大堆公式吓人;学生则死啃书本,然后突然顿悟。针对入门者的教材不应该是这样的。(看到一位知乎的大佬说的, 深有感悟~) 动态规划 就是 : 给定一个问…
C++的cin和cout加快读写速度,用以下代码: std::ios::sync_with_stdio(false); std::cin.tie(0);
原题单链接:https://www.luogu.com.cn/paste/sa0zary9 || https://rentry.org/3r68rga7 广度优先搜索算法(Breadth First Search),又称为"宽度优先搜索", BFS是用于图的查找算法(要求能用图表示出问题的关联性)。 BFS可用于解决2类问题: 1.从A出发是否存在…
原题单链接:https://www.luogu.com/paste/vjf2z3hi || https://rentry.org/5yhk52ow 例题 跳台阶 #include <bits/stdc++.h> using namespace std; const int N=1e5; int a[N]; int f(int n) { …
十进制转其他进制 #include <bits/stdc++.h> using namespace std; string s="0123456789ABCDEF"; void solve(int x,int m) { // 递归 if(x/m) solve(x/m,m); cout<<s[x%m]; /…
// 计算两个数的 GCD int gcd(int a, int b) { while (b) // b!=0 { int r = a % b; a = b; b = r; } return a; } // 计算两个数的 LCM int lcm(int a, int b) { return a / gcd(a, b) * b; // 先除后乘,避免…