dp
Ostrichcrab
这个作者很懒,什么都没留下…
展开
-
dp训练 51nod 1006
先跑一遍lcs得到最长公共子序列长度,再倒着跑一遍记录路径,即dp[i][j]刚开始发生改变的地方#include<bits/stdc++.h>using namespace std;const int maxn = 1010;char s1[maxn],s2[maxn],path[maxn];int dp[maxn][maxn];int len1,len2;void...原创 2018-07-29 15:35:11 · 119 阅读 · 0 评论 -
dp练习 51nod1049最大字段和
注意初始化#include<bits/stdc++.h>#define ll long longusing namespace std;const int maxn = 5e4+4;ll a[maxn];int n;ll dp[maxn];ll ans;int main(){ scanf("%d",&n); bool flag = false; ...原创 2018-07-29 17:19:42 · 144 阅读 · 0 评论 -
dp测模板ORZ 51nod 1134最长递增子序列
在劝退边缘徘徊…… 复习了下lower_bound 和 upper_bound#include<bits/stdc++.h>using namespace std;const int maxn = 1e5;int dp[maxn];int a[maxn];int len=0;int n;void lis(){ len = 0; dp[0]=-0x3...原创 2018-07-30 23:36:08 · 128 阅读 · 0 评论 -
51nod 1183 编辑距离问题(dp)
编辑距离,又称Levenshtein距离(也叫做Edit Distance),是指两个字串之间,由一个转成另一个所需的最少编辑操作次数。许可的编辑操作包括将一个字符替换成另一个字符,插入一个字符,删除一个字符。例如将kitten一字转成sitting:sitten (k->s)sittin (e->i)sitting (->g)所以kitten和sitting...原创 2018-07-31 15:14:59 · 104 阅读 · 0 评论 -
51nod 1007 正整数分组(01背包变形)
01背包的变形,看成价值和重量相等的01背包,设总和为sum,则背包总容量为sum/2,往这个背包里填,使之最接近sum/2,则剩下的与装进去#include<cstdio>#include<iostream>#include<algorithm>using namespace std;const int N = 100;const int M ...原创 2018-08-07 22:05:17 · 110 阅读 · 0 评论 -
LeetCode 213. House Robber II
//This problem is a little tricky at first glance. However, if you have finished the House Robber problem, this problem can simply be decomposed into two House Robber problems.// Suppose there are n...原创 2019-01-28 20:35:16 · 115 阅读 · 0 评论 -
记忆化搜索 动态规划 LeetCode329 longest-increasing-path-in-a-matrix
LeetCode329 矩阵里的最长上升子序列f[x][y]表示走到(x,y)的最长上升子序列的长度dfs(x,y)递归搜索,返回f[x][y]的值刚开始f[][]全部初始化为-1,表示还没有计算过每个状态只会被计算一次状态转移:f[x][y] = max(f[x][y],dfs(a,b)+1); ((a,b)的值要比(x,y)的值小才可以转移)class Soluti...原创 2019-02-16 13:41:10 · 132 阅读 · 0 评论