uva 10066 The Twin Towers (最长公共子)
uva 10066 The Twin Towers
标题效果:最长公共子。
解题思路:最长公共子。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int a[105], b[105], dp[105][105];
int main() {
int n, m, Case = 1;
while (scanf("%d %d", &n, &m) == 2) {
if (n == 0 && m == 0) break;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < m; i++) {
scanf("%d", &b[i]);
}
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i - 1] == b[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
}
else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
printf("Twin Towers #%d\n", Case++);
printf("Number of Tiles : %d\n\n", dp[n][m]);
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
uva 10066 The Twin Towers (最长公共子)的更多相关文章
- UVA.10066 The Twin Towers (DP LCS)
UVA.10066 The Twin Towers (DP LCS) 题意分析 有2座塔,分别由不同长度的石块组成.现在要求移走一些石块,使得这2座塔的高度相同,求高度最大是多少. 问题的实质可以转化 ...
- UVa 10192 - Vacation & UVa 10066 The Twin Towers ( LCS 最长公共子串)
链接:UVa 10192 题意:给定两个字符串.求最长公共子串的长度 思路:这个是最长公共子串的直接应用 #include<stdio.h> #include<string.h> ...
- UVA 10066 The Twin Towers
裸最长公共子序列 #include<time.h> #include <cstdio> #include <iostream> #include<algori ...
- UVA 10066 The Twin Towers(LCS)
Problem B The Twin Towers Input: standard input Output: standard output Once upon a time, in an anci ...
- 使用后缀数组寻找最长公共子字符串JavaScript版
后缀数组很久很久以前就出现了,具体的概念读者自行搜索,小菜仅略知一二,不便讨论. 本文通过寻找两个字符串的最长公共子字符串,演示了后缀数组的经典应用. 首先需要说明,小菜实现的这个后缀数组算法,并非标 ...
- uva 10192 Vacation(最长公共子)
uva 10192 Vacation The Problem You are planning to take some rest and to go out on vacation, but you ...
- UVa 111 - History Grading (by 最长公共子序列 )
History Grading Background Many problems in Computer Science involve maximizing some measure accor ...
- UVA 12511/CSU 1120 virus 最长公共上升子序列
第一次接触一个这最长公共上升子序列 不过其实搞清楚了跟最长公共子序列和 最长上升子序列如出一辙 两重循环,对于当前不相等的,等于前一个的值,相等的,等于比当前A[i]小的最大值+1.弄个临时变量记录最 ...
- LIS(最长的序列)和LCS(最长公共子)总结
LIS(最长递增子序列)和LCS(最长公共子序列)的总结 最长公共子序列(LCS):O(n^2) 两个for循环让两个字符串按位的匹配:i in range(1, len1) j in range(1 ...
随机推荐
- UVA 10160 Servicing Stations(深搜 + 剪枝)
Problem D: Servicing stations A company offers personal computers for sale in N towns (3 <= N < ...
- [ACM] 九度OJ 1553 时钟
时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:1733 解决:656 题目描写叙述: 如图,给定随意时刻,求时针和分针的夹角(劣弧所相应的角). 输入: 输入包括多组測试数据.每组測试数 ...
- Swift - 给表格TableView添加页眉和页脚
UITableView具有var tableHeaderView:UIView?属性和var tableFooterView:UIView?属性,可以通过给其赋值来创建列表TableView的页眉和页 ...
- EL表达式(3)
本篇讲解使用EL表达式来调用Java方法(自定义EL函数)和Sun公司开发的EL函数库. 简单来说,我们在一个类中的某个方法,可以使用EL进行调用,这个能被EL表达式调用的方法称之为EL函数,但是这种 ...
- Ace of Aces
Description There is a mysterious organization called Time-Space Administrative Bureau (TSAB) in the ...
- 让进程在后台可靠运行的几种方法 nohup,setsid,&,disown,CTRL-z ,screen
让进程在后台可靠运行的几种方法 几年前在developerWorks上面看到的文章,感觉非常实用,又简单整理了一下,转到这里,希望给看到的人带来一些帮助.文中提到的nohup和subshell方式一直 ...
- uva 12300 - Smallest Regular Polygon
题意:给定两个点A和B,求包含这两个点的面积最小的正 n(已知)边形. #include<iostream> #include<iomanip> #include<cma ...
- Swift - 给表格添加Cell的显示动画(3D缩放)
下面的一个样例是让tableView显示数据的时候具有一个很炫的3D缩放效果. 我们只需要实现tableView的willDisplayCell方法.看方法名就知道这是在Cell将要显示的时候执行的方 ...
- Oracle 执行计划了的rows概念
alter session set statistics_level=all; select t1.* from t1,t2 where t1.id=t2.id and t1.id<3; sel ...
- 特么的. 最终把 amobbs 的站长阿莫(莫进明)给回骂了一顿.
起因: 假设你居住的地方,要上马PX等高污染的项目,你会怎么做. 鼓动别人上街暴力示威与军警对抗. 自己待在家里支持怂恿. 这样的人真心猥琐! 鉴于他常常私自改动帖子, 在此截图留存. 真特么没劲. ...