随笔分类 - 动态规划
摘要:f[i]表示一定选a[i]的字串的最大值 #include <cstdio> #include <algorithm> using namespace std; typedef long long ll; const int maxn = 1005; const int inf=1e9; int n
阅读全文
摘要:#include <cstdio> #include <algorithm> using namespace std; typedef long long ll; const int maxn = 1005; int n, k; int a[maxn],f[maxn]; //最长不下降子序列 int
阅读全文
摘要:https://ac.nowcoder.com/acm/contest/19506/F 没注意到输入里有个k,循环里也用了个k; dp[i][j]表示i个盒子放j本书的最小面积 #include <cstdio> #include <algorithm> using namespace std; t
阅读全文
摘要:题目: https://www.luogu.com.cn/problem/P4084 如果被染色了,只有一种染色方式,其他的为0 没被染色的,三种都可以 链式前向星存图 #include<stdio.h> typedef long long ll; const int maxn=1e5+7; con
阅读全文
摘要:题目: https://www.luogu.com.cn/problem/P3205 dp[i][j][0]表示第i个数从左边进 dp[i][j][1]表示第j个数从右边进 注意处理边界属于等价的情况,只用算一遍 #include<stdio.h> #include<algorithm> #incl
阅读全文
摘要:题目: https://www.luogu.com.cn/problem/P1063 #include<stdio.h> #include<algorithm> #include<string.h> #include<queue> using namespace std; typedef pair<
阅读全文
摘要:题目: https://www.luogu.com.cn/problem/P1880 题目描述 在一个圆形操场的四周摆放 NN 堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分。 试设计出一个算法,计算出将 NN 堆石子合并成 1
阅读全文
摘要:#include<stdio.h> #include<algorithm> #include<queue> using namespace std; typedef pair<int ,int > p; typedef long long ll; int xa,ya,xm,ym; ll c[22][
阅读全文
摘要:题目:https://www.luogu.com.cn/problem/P1091 思路: 相当于要求最长先升后降的序列 拆开来看,先从左到右求一遍最长不下降子序列 再从右到左求一遍最长不下降子序列 再枚举求最大值 #include<stdio.h> #include<algorithm> usin
阅读全文
摘要:题目: https://www.luogu.com.cn/problem/P1144 用bfs来求最短路,用dep数组来表示深度,用c数组来表示从1到达当前状态的数量 如果当前的dep[w]==dep[te]+1的话就把到达te的次数加给w 代码: #include<stdio.h> #includ
阅读全文
摘要:题目: https://www.luogu.com.cn/problem/P1439 离散化+最长公共子序列的优化 离散化的例子:求2314 和3142的最长公共子序列2 3 1 4 1 2 3 4 3 1 4 2 2 3 4 1 #include<stdio.h> #include<algorit
阅读全文
摘要:题目: https://www.luogu.com.cn/problem/P2758 代码: //#define DEBUG #include<iostream> #include<stdio.h> #include<cstring> #include<math.h> #include<algori
阅读全文
摘要:题目: https://ac.nowcoder.com/acm/contest/9981/A 题目大意: 长度不超过n,且包含子序列“us”的、只由小写字母构成的字符串有多少个? 答案对109+710^9+7109+7取模。 所谓子序列,指一个字符串删除部分字符(也可以不删)得到的字符串。 例如,"
阅读全文
摘要:题目: https://ac.nowcoder.com/acm/problem/107076 题解: 先从左到右遍历一遍,求出到每个点为止的最大序列 要把le[1]单独拿出来,如果和后面一起放到循环里会出错,因为会有负数 同理后面的ri[n] r[n]都要把最后一个单独拿出来 最后再遍历断点 (ps
阅读全文
摘要:链接:https://ac.nowcoder.com/acm/problem/16693来源:牛客网 题目描述 有一个箱子容量为V(正整数,0 ≤ V ≤ 20000),同时有n个物品(0<n ≤ 30),每个物品有一个体积(正整数)。 要求n个物品中,任取若干个装入箱内,使箱子的剩余空间为最小。
阅读全文
浙公网安备 33010602011771号