uva 111 History Grading(动态规划:LCS)
来源:互联网 发布:java命令运行jar包 编辑:程序博客网 时间:2024/06/06 04:43
水题一个
但是并不是对输入直接求LCS
输入指的是对应下标在真正序列中应该处在的位置
预处理下即可
代码如下:
#include <cstdio>#include <cstring>#include <algorithm>#define MAXN 100using namespace std;int a[MAXN], b[MAXN], dp[MAXN][MAXN];int get_lcs(int n) { memset(dp, 0, sizeof(dp)); for(int i=1; i<=n; ++i) { for(int j=1; j<=n; ++j) { if(a[i] == b[j]) dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1); else dp[i][j] = max(dp[i-1][j], dp[i][j-1]); } } return dp[n][n];}int main(void) { int n, x; scanf("%d", &n); for(int i=1; i<=n; ++i) { scanf("%d", &x); a[x] = i; } while(scanf("%d", &x) != EOF) { b[x] = 1; for(int i=2; i<=n; ++i) { scanf("%d", &x); b[x] = i; } printf("%d\n", get_lcs(n)); memset(b, 0, sizeof(b)); } return 0;}
0 0
- UVA - 111 History Grading (动态规划:LCS)
- uva 111 History Grading(动态规划:LCS)
- UVA 111 - History Grading(动态规划)
- uva 111 - History Grading(LCS)
- Uva 111-History Grading(DP/LCS)
- UVA - 111 - History Grading (LCS)
- uva 111 History Grading 动态规划
- uva 111 - History Grading LCS
- uva 111 History Grading(LCS)
- UVA 111 History Grading 【lcs】
- uva History Grading lcs
- UVA 111 History Grading(dp + LCS)
- UVa 111 History Grading (DP&LCS)
- UVa 111|History Grading|动态规划|最长上升子序列
- History Grading(uva 111)
- UVa 111 - History Grading
- uva 111 History Grading
- [UVA 111] History Grading
- 管理员取得所有权
- c++学习日志 求最大公约数
- Android WebView 开发详解(一)
- matlab 分段函数 反余弦
- 重载操作符
- uva 111 History Grading(动态规划:LCS)
- 新浪API(Java)使用方法
- 织梦DedeCms系统标签autoindex和itemindex用法说明
- Uva 11021 Tribles
- linux下音乐播放器wav和mp3
- 设计模式之抽象工厂模式(可用于项目实战)
- oralce对用户的解锁和改密码
- DTU+TCP+udp转+GRidvis
- fdgjhgfjgj