题意:

最长公共子序列。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <map>#define LL long longusing namespace std;
const int maxn = 100 + 10;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = 4 * atan(1.0);
const double ee = exp(1.0);int a1[maxn], a2[maxn];
int dp[maxn][maxn];int main()
{#ifdef LOCALfreopen("in.txt", "r", stdin);#endif // LOCALint n1, n2;int ncase = 1;while (scanf("%d%d", &n1, &n2) == 2){if (n1 == 0 && n2 == 0)break;for (int i = 0; i < n1; i++){scanf("%d", &a1[i]);}for (int i = 0; i < n2; i++){scanf("%d", &a2[i]);}memset(dp, 0, sizeof(dp));for (int i = 1; i <= n1; i++){for (int j = 1; j <= n2; j++){if (a1[i - 1] == a2[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", ncase++);printf("Number of Tiles : %d\n\n", dp[n1][n2]);}return 0;
}

uva 10066 LCS相关推荐

  1. UVa 10192 - Vacation amp; UVa 10066 The Twin Towers ( LCS 最长公共子串)

    链接:UVa 10192 题意:给定两个字符串.求最长公共子串的长度 思路:这个是最长公共子串的直接应用 #include<stdio.h> #include<string.h> ...

  2. UVa 10066 - The Twin Towers(LCS水题)

    题目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...

  3. UVa 10066 Twin Towers (DP 最长公共子序列)

    题意  求两串数字最长公共子序列的长度 裸的lcs没啥说的 #include<cstdio> #include<cstring> #include<algorithm&g ...

  4. uva 10635 Prince and Princess(LCS成问题LIS问题O(nlogn))

    标题效果:有两个长度p+1和q+1该序列.的各种元素的每个序列不是相互同.并1~n^2之间的整数.个序列的第一个元素均为1. 求出A和B的最长公共子序列长度. 分析:本题是LCS问题,可是p*q< ...

  5. 判断条件UVa 10192 - Vacation(LCS水题)

    PS:今天上午,非常郁闷,有很多简单基础的问题搞得我有些迷茫,哎,代码几天不写就忘.目前又不当COO,还是得用心记代码哦! 题目:http://uva.onlinejudge.org/index.ph ...

  6. UVa在线比赛单题汇总-----DP专题

    动态规划基础 例题 LA 3882 UVa 3882 - And Then There Was One 递推------------无力orz UVa 10635 10635 - Prince and ...

  7. UVA dp题目汇总

    UVa专题练习 A-4 10003 经典dp,可用四边形不等式优化 10029 基础dp,DAG最长路,需高效构图 10032 经典问题.子集和数问题.01背包问题 10036 能否在一个整数序列的每 ...

  8. UVa Online Judge 工具網站

    UVa Online Judge 工具網站 转自http://www.csie.ntnu.edu.tw/~u91029/uva.html Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 M ...

  9. [搜索]UVa 129 困难的串

    题意:将一个包含两个相邻的重复子串的子串,称为"容易的串",其他为"困难的串". 输入正整数n和l,输出由前l个字符组成的,字典序第n小的困难的串. 输入样例: ...

  10. uva 401.Palindromes

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

最新文章

  1. MySQL 性能优化,优化设计及设计原则解读
  2. 2013年计算机专业对口模拟试题二,计算机对口升学模拟试题全解.doc
  3. 多线程情况下创建连接池
  4. 数据库计划中的14个才略
  5. python pointer_python 的隐式指针特征与class inheritance
  6. Pro*c源程序中使用宿主结构保存查询结果
  7. android打印intent flag,Android flag详解
  8. 不一样 使用别名 数据字段和bean_Mybatis-resultMap标签详解
  9. 《高并发Oracle数据库系统的架构与设计》一1.4 本章小结
  10. 循环队列(java)
  11. DOM之事件高级(附实例、图解)
  12. 安装PyQt5安装包或者其他操作,报错Failed to execute script pyi_rth_multiprocessing,解决办法
  13. select *和select 字段名
  14. linux版uTorrent安装手记
  15. 盗梦空间科普札记之一:梦里乾坤嵌套深,醒来可知在哪层?
  16. animejs走马灯_web前端攻城狮超爱的JS动画库插件—anime.js
  17. warning: #231-D: declaration is not visible outside of function
  18. css权重是什么?css权重的介绍
  19. impdp 导入报错
  20. C++静态成员对象与静态成员函数

热门文章

  1. android12适配机型,安卓12支持机型有哪些?安卓12系统为什么有的软件用不了?...
  2. python多任务爬虫(四、协程池实现爬虫)
  3. 江苏华罗庚中学2021高考成绩查询,2021年常州各高中高考成绩排名及放榜最新消息...
  4. 解决sigmoid/softmax指数运算溢出问题及python实现
  5. updating homebrew
  6. WPF使用DialogResult.OK报错
  7. Jenkins 页面不刷新最新修改配置,需要强制刷新才可以,Request Status Code:200 OK (from disk cache)
  8. Facebook广告的基础认知,看一下你是否了解
  9. 神经内分泌肿瘤如何分级,神经系统分级调节概念
  10. 使用Foxmail 登录qq邮箱使用第三发授权码登录失败