摘要: 知识点:多重背包,也就是一个物品有多个,然后求总价值。 算法竞赛上的板子题目: 链接:https://www.luogu.com.cn/problem/P1776 介绍二进制拆分优化 就是把几个完全相同的拆成1+2+4+...+2^n+mod,然后再进行dp的办法 代码: 重点在new_n,new_ 阅读全文
posted @ 2024-04-04 12:17 WHUStar 阅读(70) 评论(0) 推荐(0)
摘要: 题目: 链接:https://www.luogu.com.cn/problem/P1077 总的来说就是和上题差不多? 记dp[i][j]为前i种花塞进了j的背包的种类,那么状态转移方程: 就是:dp[i][j] = dp[i-1][j] + dp[i-1]j-k 贴代码: #include<ios 阅读全文
posted @ 2024-04-04 11:06 WHUStar 阅读(58) 评论(0) 推荐(0)
摘要: 这种的动态规划题目主要还是不能被自己的思路限制了,之前的dp[i][j]是“最大值”; 这里得把dp[i][j]理解为前i个物品放到j容的背包中的方法; 那么很显然有递推公式: 代码: #include<iostream> #include<vector> #include<algorithm> # 阅读全文
posted @ 2024-04-04 10:15 WHUStar 阅读(44) 评论(0) 推荐(0)
摘要: 题面: 链接:https://www.luogu.com.cn/problem/solution/P1616 类型:完全背包模板 完全背包感觉也可以用普通的0/1背包去写,但是似乎时间不够? 总之这种题目的模板就是一个一维数组dp,然后空间从t[i]遍历到times,这样可以实现多个t[i]相加 这 阅读全文
posted @ 2024-04-04 09:48 WHUStar 阅读(13) 评论(0) 推荐(0)
摘要: emmmm...据说是比较简单的dp?(再一次意识到自己的菜) 链接:https://www.luogu.com.cn/problem/P1002 题目: 总的思路就是一个状态转移方程吧: dp[x][y] = dp[x-1][y] + dp[x][y-1]; 然后如果发现这个点不能通过,那么强制修 阅读全文
posted @ 2024-04-03 22:19 WHUStar 阅读(36) 评论(0) 推荐(0)
摘要: 链接:https://www.luogu.com.cn/problem/P1802 额,dp的板子?差不多,就加一个变式就行( 代码: #include<iostream> #include<vector> #include<algorithm> #include<math.h> #include< 阅读全文
posted @ 2024-04-03 21:42 WHUStar 阅读(15) 评论(0) 推荐(0)
摘要: 链接:https://www.luogu.com.cn/problem/P1434 题目: 思路:找每个点的小于链的长度,存在lenless里;找每个点的大于链,存在于lengreat中。 然后两个相加,排序,选择最大的那个数字。注意这里长度要加1,因为没有加上自己的(初始数据设置成0)! (按理说 阅读全文
posted @ 2024-04-03 15:32 WHUStar 阅读(30) 评论(0) 推荐(0)
摘要: 书上讲的感觉不好理解,不如算法竞赛上分析的 题目链接: https://www.luogu.com.cn/problem/P3375 贴板子: #include<iostream> #include<vector> #include<algorithm> #include<math.h> #incl 阅读全文
posted @ 2024-04-02 12:16 WHUStar 阅读(25) 评论(0) 推荐(0)
摘要: #include<iostream> #include<vector> #include<algorithm> #include<math.h> #include<sstream> #include<string> #include<string.h> #include<iomanip> #incl 阅读全文
posted @ 2024-04-01 22:11 WHUStar 阅读(11) 评论(0) 推荐(0)
摘要: 拓扑排序的模板,csdn:https://blog.csdn.net/weixin_43872728/article/details/98981923 #include <iostream> #include <vector> #include <cstdio> #include <queue> # 阅读全文
posted @ 2024-03-31 17:01 WHUStar 阅读(9) 评论(0) 推荐(0)