04 线性DP
作者:互联网
数字三角形(也可以使用记忆化搜索来做)
原题链接 https://www.acwing.com/problem/content/900/
# 顺推
#include<bits/stdc++.h>
using namespace std;
const int N = 510;
const int INF = 0x3f3f3f3f;
int f[N][N];
int a[N][N];
int main()
{
int n;
cin>>n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= i; j++)
cin>>a[i][j];
for (int i = 1; i <= n; i++) memset(f[i], -INF, sizeof(f[i]));
f[1][1] = a[1][1];
for (int i = 2; i <= n; i++){
for (int j = 1; j <= i; j++) {
f[i][j] = max(f[i - 1][j], f[i -1][j - 1]) + a[i][j];
}
}
int ans = - INF;
for (int i = 1; i <= n; i++) ans = max(ans, f[n][i]);
cout<<ans<<endl;
return 0;
}
最长上升子序列
原题链接 https://www.acwing.com/activity/content/problem/content/1003/
最长公共子串
最长公共子序列
编辑距离
标签:www,const,04,原题,int,content,https,线性,DP 来源: https://www.cnblogs.com/dacyuan/p/15514266.html