随笔分类 - 动态规划
摘要:"金明的预算方案" 思路: 观察题面的描述,不难发现对于每个主件,最多只存在有2个附件,所以我们可以对每一个主件进行暴力枚举。在01背包的for循环中,对于每一个主件,有五种选择: 1.不买该主件。 2.仅买该主件。 3.买主件和附件1. 4.买主件和附件2. 5.买主件以及两个附件。 Code:
阅读全文
摘要:"数的划分" Code: c++ include include include using namespace std; //Mystery_Sky // define M 500 define INF 0x3f3f3f3f int f[M][M], n, k; int main() { scan
阅读全文
摘要:"花店橱窗布置" 里程碑式的一题! 第一次完全未看题解做出的一道dp题 Code: c++ include include include using namespace std; //Mystery_Sky // define M 500 define INF 0x3f3f3f3f int f[M
阅读全文
摘要:"书的复制" Code: c++ include include include using namespace std; //Mystery_Sky // define M 700 define INF 0x3f3f3f3f int f[M][M], sum[M], a[M]; int n, k;
阅读全文
摘要:"计算字符串距离" 同样也是字符串距离计算问题,参考 "一本通 1276:【例9.20】编辑距离" Code: c++ include include include using namespace std; //Mystery_Sky // define INF 0x3f3f3f3f define
阅读全文
摘要:"滑雪" 记忆化搜索 Code: c++ include include include using namespace std; //Mystery_Sky // define M 500 define INF 0x3f3f3f3f int f[M][M]; int r, c, map[M][M]
阅读全文
摘要:"编辑距离" Code: c++ include include include using namespace std; //Mystery_Sky // define INF 0x3f3f3f3f define M 3000 int f[M][M]; int len_a, len_b; char
阅读全文
摘要:"乘积最大(数据弱化版)" ps:本题无需使用大整数。 Code: c++ include include include using namespace std; //Mystery_Sky // define INF 0x3f3f3f3f define M 500 int f_max[M][M]
阅读全文
摘要:"合并石子" 状态转移方程:f_min[i][i] = 0, f_min[i][j] = min(f_min[i][k] + f_min[k+1][j] + sum[j] sum[i 1]; Code: c++ include include include using namespace std;
阅读全文
摘要:"友好城市" 对北岸(或南岸)的城市从小到大排序,再求南岸(或北岸)的城市位置的最长不下降序列长度即可。 ps:这里数据较弱,用n n的做法可以过。 Code: c++ include include include include using namespace std; //Mystery_Sk
阅读全文
摘要:"机器分配" Code: c++ include include include using namespace std; //Mystery_Sky // define M 5000 int f[M][M]; int n, m, ans; int c[M][M]; void print(int i
阅读全文
摘要:"开餐馆" 01背包的变式 Code:
阅读全文
摘要:"分组背包" 分组背包模板题 Code:
阅读全文
摘要:"宠物小精灵之收服" 二维费用背包 Code: c++ include include include include using namespace std; //Mystery_Sky // define M 5000 int f[M][M]; int n, m, k; int a[M], b[
阅读全文
摘要:"潜水员" 二维费用背包 Code:
阅读全文
摘要:"混合背包" 混合背包模板题。
阅读全文
摘要:"数字组合" 01背包的变式。 做完这道题之后建议去做一做 "货币系统" 。
阅读全文
摘要:"买书" "货币系统" 的简化版,注意特判0。 cpp include include using namespace std; //Mystery_Sky // define ll long long define M 10000 int v, m; ll c[M], f[M]; int main
阅读全文