随笔分类 -  ACM--DP--线性dp

该文被密码保护。
posted @ 2020-11-13 12:17 swsyya 阅读(0) 评论(0) 推荐(0)
该文被密码保护。
posted @ 2020-10-14 12:01 swsyya 阅读(0) 评论(0) 推荐(0)
该文被密码保护。
posted @ 2020-10-12 14:50 swsyya 阅读(0) 评论(0) 推荐(0)
摘要:题目链接:here 题解:对于不带限制的最大字段和我们可以:求一遍前缀和,求出最大值最小值,最后结果 res = max( MAX, SUM - MIN ); 那么对于这道题相当于带了限制:限制最大子段的长度是len:我们可以维护一个前缀和 ,然后结果就是 max( sum[i] - min(sum 阅读全文
posted @ 2020-09-16 20:05 swsyya 阅读(222) 评论(0) 推荐(0)
摘要:测试地址:here AC_Code: 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 typedef unsigned long long ull; 5 const int maxn = 1010 阅读全文
posted @ 2020-08-03 11:45 swsyya 阅读(118) 评论(0) 推荐(0)
摘要:Maximum Sum on Even Positions 解题思路: 首先,我们知道:如果选择某个子段倒序,那么子段长度一定是偶数,因为如果是奇数长度,那么原来在奇数位置的数还在奇数位置,原来在偶数位置的数还在偶数位置,这对题目要求来说是没有意义的。 那么有两种情况:第一种: 1,2,3,4,5, 阅读全文
posted @ 2020-07-08 17:22 swsyya 阅读(330) 评论(0) 推荐(0)
摘要:选点 分析:对于一颗树选出得点的权值的关系为:根节点 < 右子树 < 左子树。所以我们可以按照根节点、右子树、左子树进行 dfs 遍历,然后按照这个 dfs 序求 LIS 即为答案。用二分优化求LIS AC_Code 1 #include <iostream> 2 #include <bits/st 阅读全文
posted @ 2020-02-24 10:09 swsyya 阅读(307) 评论(0) 推荐(0)
摘要:相似基因 很好的题解 1.dp 基本思路 dp 题基本这么几个步骤: 定义状态。 写出状态转移式。 根据状态转移式找出递推顺序。 处理递推的边界。 找出结果。 我讲解时不会就题论题,而是讲大部分黄绿难度的 dp 题的方法。 当然,dp 题十分灵活,不会看完这篇题解就会做,关键在于大量的练习。 2.状 阅读全文
posted @ 2020-01-31 18:28 swsyya 阅读(210) 评论(0) 推荐(0)
摘要:数的划分 1 //设f(n,k)为整数n拆分成k个数字的方案数,则可以分以下两种情况讨论。 2 //(1)拆分的结果不包含1的情况:如果不包含1,我们把n拆分成k块时可以看做先将每一块加上个1,则n还剩余n-k,即f(n-k,k) 3 //(2)拆分的结果包含1的情况:那么就直接选一个1,即f(n- 阅读全文
posted @ 2020-01-31 17:21 swsyya 阅读(355) 评论(0) 推荐(0)
摘要:小a的子序列 【题目描述】小a有一个长度为n的序列,但是他忘了这个序列的样子,他只记得序列中的数大小在[1,V]内,你可以任意选择一些位置,并给它们赋值来组成一段子序列,需要满足序列中的数严格递增,一段子序列的“萌值”定义为序列中除最大数外所有数的乘积,若只有1个数则为1。 他想请你求出所有合法子序 阅读全文
posted @ 2020-01-31 15:57 swsyya 阅读(131) 评论(0) 推荐(0)
该文被密码保护。
posted @ 2020-01-31 11:07 swsyya 阅读(76) 评论(0) 推荐(0)
摘要:最长公共子上升序列 AC_Code 1 #include <iostream> 2 #include <cstdio> 3 #include <string> 4 #include <cstring> 5 #include <string> 6 #include <cmath> 7 #include 阅读全文
posted @ 2020-01-31 09:59 swsyya 阅读(205) 评论(0) 推荐(0)
摘要:回文字符串 思路:由于要找最少添加的字符使得原字符串变为回文串,那么先将给出的字符串反转,将两字符串做 LCS,得到的是最大的公共子串的长度,那么用字符串长度减去最大公共子串长度就是最少添加字符的个数 1 #include <iostream> 2 #include <cstdio> 3 #incl 阅读全文
posted @ 2020-01-31 09:21 swsyya 阅读(227) 评论(0) 推荐(0)
摘要:友好城市 解题思路:不交叉,则将北岸的坐标从小到大排,找南岸的最长上升子序列 AC_Code 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include <algorithm> 5 #include <bits/st 阅读全文
posted @ 2020-01-30 23:02 swsyya 阅读(177) 评论(0) 推荐(0)
摘要:免费馅饼 数字三角形变形: AC_Code 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <cmath> 6 #include <algorithm> 7 u 阅读全文
posted @ 2020-01-30 22:25 swsyya 阅读(107) 评论(0) 推荐(0)
摘要:【最长子序列和】 问题定义:对于给定序列 a1,a2,a3……an 寻找它的某个连续子段,使得其和最大。 模板: 1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn = 阅读全文
posted @ 2020-01-29 16:28 swsyya 阅读(203) 评论(0) 推荐(0)
摘要:https://www.cnblogs.com/wsy107316/p/11502628.html 导弹拦截 解题思路:用nlogn的方法求第一问:最长不上升序列:方法链接 用贪心法求第二问,遍历一遍 AC_Code: 1 #include <iostream> 2 #include <cstdio 阅读全文
posted @ 2020-01-29 12:54 swsyya 阅读(184) 评论(0) 推荐(0)
摘要:登山(LIS变形) 注意读题:不连续两个相同海拔,所以要么严格递增,要么严格递减 AC_Code 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <cmath> 阅读全文
posted @ 2020-01-29 10:30 swsyya 阅读(169) 评论(0) 推荐(0)
摘要:挖地雷(LIS变形) AC_Code: 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #include <cstring> 5 #include <cstdlib> 6 #include <string> 7 #incl 阅读全文
posted @ 2020-01-29 09:52 swsyya 阅读(187) 评论(0) 推荐(0)
摘要:Monkey and Banana AC_Code: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 typedef long 阅读全文
posted @ 2020-01-28 20:51 swsyya 阅读(172) 评论(0) 推荐(0)

回到顶部