
动态规划
浑水摸鱼拒绝996福报
这个作者很懒,什么都没留下…
展开
-
合唱队 区间dp
该题目要求我们得到一个目标序列,求所有原始序列能得到这个目标序列的数量根据题目要求数据插入顺序为从左到右,如果比前一个数大就到序列最右,如果比前一个数小,就到序列的最左边,那么如果我们要满足目标序列,我们就需要从目标序列出发,且目标序列中相邻的两个数,后一个数则必须插入前一个数的左边或者右边才能满足目标式子 .总结一下就是:左端点的数只与下一个或者右端点的在初始序列中相邻,右端点的数只与前一个或者左端点的在初始序列中相邻// 合唱队.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结原创 2021-10-15 20:32:44 · 170 阅读 · 0 评论 -
字符串折叠
该题与一般的区间dp有点区别在于我们的dp值是由该序列可否折叠得来,与一般的动态规划的转移方程是不一样的,这题区间的dp值体现从i到j最小的折叠数,可能这个折叠有1也就是不折叠,或者2,3,4取决于这个序列的长度,所以我们的dp值是由更小的序列最优值得来的,所以很明显我们需要使用区间dp的思想。// 字符串折叠.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。//#include <iostream>#include<string>#include原创 2021-10-13 19:48:59 · 260 阅读 · 0 评论 -
2021-09-29
、// 矩阵取数.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。//#include <iostream>#include<algorithm>#include<cstring>#include<string>using namespace std;const int maxn = 100;int n, c;int dp[maxn][maxn][2];//dp的意义是将从i到j的所有灯全部关掉的最小的代价,而第三原创 2021-09-29 20:31:45 · 77 阅读 · 0 评论 -
石头合并 DP区间
// 石子取数.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。//#include <iostream>#include<algorithm>#include<cstring>#include<string>//区间dp经典例题,如果能随机将两个石碓堆在一起的话,那就是哈弗曼树贪心问题了//这题石头是排成一个环的,区间DP就是从一个个小区间推出一个大区间,当然视题目而定也有状态转移而来的区间.using namesp原创 2021-09-28 20:55:54 · 107 阅读 · 0 评论 -
乌龟棋 dp
// 乌龟棋.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。//#include <iostream>#include<algorithm>#include<cstring>#include<string>using namespace std;const int maxn = 50;int f[maxn][maxn][maxn][maxn];int number[100000];int M[10];bool原创 2021-09-24 19:18:34 · 115 阅读 · 0 评论 -
传纸条 DP
// 传纸条.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。//#include <iostream>#include<algorithm>#include<cstring>#include<string>using namespace std;const int maxn = 70;int d[maxn][maxn][maxn][maxn];int dp[2*maxn][maxn][maxn];int vis[原创 2021-09-24 16:58:06 · 131 阅读 · 0 评论 -
完美的服务
// 完美的服务.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。//#include <iostream>#include<algorithm>#include<cstring>#include<string>using namespace std;const int maxn = 50000;struct edge { int to; int next;};edge edges[maxn];//前向星存图原创 2021-09-15 21:03:29 · 94 阅读 · 0 评论 -
2021-09-13
// 贪吃的九头蛇.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。////这个题显然是一个树形dp。我们先来总结一下树形dp的套路://定义f数组意义,注意要考虑到题目的一些特殊要求(比如本题的大头),还要考虑到如何输出结果。//思考如何将一个点的所有f值由这个点的儿子节点转移过来,即我们常说的状态转移方程。//将方程放到dfs深搜中更新f值,最终输出答案。别人总结的套路#include <iostream>#include<algorithm原创 2021-09-13 16:22:25 · 100 阅读 · 0 评论 -
劲爆金曲解析
// 劲歌金曲.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。//#include <iostream>#include<algorithm>#include<cstring>#include<string>using namespace std;int song;int dp[180 * 50 + 678 + 10];int n;int main(){ //这题我本来想着用二维数组来做,但其实用滚动数组来做就原创 2021-09-09 20:36:31 · 88 阅读 · 0 评论 -
最长公共子序列
// 最长公共子序列.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。//#include <iostream>#include<algorithm>#include<cstring>#include<string>using namespace std;const int maxn = 100005;int dp[maxn];int a[maxn];int map[maxn];int b[maxn];/*/原创 2021-09-09 20:23:19 · 104 阅读 · 0 评论 -
最小回文串记录
// 最小回文串.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。//#include <iostream>#include<algorithm>#include<cstring>#include<string>using namespace std;string s;const int maxn = 1005;int temp[maxn][maxn];int d[maxn];/*bool pre_slove(原创 2021-09-09 20:05:14 · 166 阅读 · 0 评论