随笔分类 - 有趣的算法题
摘要:题目 题解 #include <iostream> #include <cstring> using namespace std; typedef long long LL; const int N = 3; int n, m; void mult(int c[], int a[], int b[]
阅读全文
摘要:题目 题解 动态规划 用二进制表示每种味道尝了没有,如:一共有五种味道,吃了前三种——00111,吃了五种——11111 每包糖果都可以选或不选 dp(i,j) i代表前i包糖果, j代表所能到达的状态(吃了几种种味) 其实就是01背包问题 dp[i-1][j & (~w[i])]+1 意味着:选这
阅读全文
摘要:题目 题解 #include <iostream> using namespace std; int k; string str; int dfs() { int res = 0; while(k < str.size()) { if(str[k] == '('){ //处理(.....) k ++
阅读全文
摘要:题目 题解 #include <iostream> #include <algorithm> using namespace std; typedef long long LL; const int N = 110; int n; int cnt; LL a[N],b[N],c[N]; //a为分子
阅读全文
摘要:题解 代码 #include <iostream> #include <cstdio> using namespace std; typedef long long LL; LL exgcd(LL a,LL b,LL &x,LL &y) { if(!b){ x = 1, y = 0; return
阅读全文
摘要:题解 加入一个超级源点,到各个商店之间的距离为0,对商店求单源最短路,那么各个村庄到源点的最短距离就是到其最短商店的距离 vector成邻接表 #include <iostream> #include <vector> #include <cstring> #include <queue> #def
阅读全文
摘要:原题链接:https://www.luogu.com.cn/problem/P1075 题解:这道题数据很大,预处理质数明显不行,故我们需要进行质因数分解(若其最大质因数是其本身)。首先我们要明确一个概念任何数都是质因数组成,如4由2组成,8由2组成,9由3组成等等。。。。 故这个数若不能被质因数2
阅读全文