链接:UVa 10192

题意:给定两个字符串。求最长公共子串的长度

思路:这个是最长公共子串的直接应用

#include<stdio.h>
#include<string.h>
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
char s[105],t[105];
int i,j,k=0,m,n,dp[105][105];
while(gets(s)!=NULL){
if(strcmp(s,"#")==0)
break;
k++;
gets(t);
m=strlen(s);
n=strlen(t);
for(i=0;i<m;i++)
dp[i][0]=0;
for(i=0;i<n;i++)
dp[0][i]=0;
for(i=0;i<m;i++)
for(j=0;j<n;j++){
if(s[i]==t[j])
dp[i+1][j+1]=dp[i][j]+1;
else
dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
}
printf("Case #%d: you can visit at most %d cities.\n",k,dp[m][n]);
}
return 0;
}

option=com_onlinejudge&Itemid=8&category=12&page=show_problem&problem=1007">链接:UVa 10066

题意:求给定两个字符串的最长公共子串

#include<stdio.h>
int m,n,a[105],b[105],dp[105][105];
int max(int a,int b)
{
return a>b? a:b;
}
void LCS()
{
int i,j;
for(i=1;i<=m;i++)
dp[i][1]=0;
for(j=1;j<=n;j++)
dp[1][j]=0;
for(i=1;i<=m;i++)
for(j=1;j<=n;j++){
if(a[i]==b[j])
dp[i+1][j+1]=dp[i][j]+1;
else
dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
}
}
int main()
{
int i,k=0;
while(scanf("%d%d",&m,&n)!=EOF){
if(m==0&&n==0)
break;
k++;
for(i=1;i<=m;i++)
scanf("%d",&a[i]);
for(i=1;i<=n;i++)
scanf("%d",&b[i]);
LCS();
printf("Twin Towers #%d\n",k);
printf("Number of Tiles : %d\n\n",dp[m+1][n+1]);
}
return 0;
}

UVa 10192 - Vacation &amp; UVa 10066 The Twin Towers ( LCS 最长公共子串)的更多相关文章

  1. uva 10066 The Twin Towers (最长公共子)

    uva 10066 The Twin Towers 标题效果:最长公共子. 解题思路:最长公共子. #include<stdio.h> #include<string.h> # ...

  2. uva 10192 Vacation(最长公共子)

    uva 10192 Vacation The Problem You are planning to take some rest and to go out on vacation, but you ...

  3. UVA.10192 Vacation (DP LCS)

    UVA.10192 Vacation (DP LCS) 题意分析 某人要指定旅游路线,父母分别给出了一系列城市的旅游顺序,求满足父母建议的最大的城市数量是多少. 对于父母的建议分别作为2个子串,对其做 ...

  4. UVA.10066 The Twin Towers (DP LCS)

    UVA.10066 The Twin Towers (DP LCS) 题意分析 有2座塔,分别由不同长度的石块组成.现在要求移走一些石块,使得这2座塔的高度相同,求高度最大是多少. 问题的实质可以转化 ...

  5. UVA 10066 The Twin Towers

    裸最长公共子序列 #include<time.h> #include <cstdio> #include <iostream> #include<algori ...

  6. UVA 10066 The Twin Towers(LCS)

    Problem B The Twin Towers Input: standard input Output: standard output Once upon a time, in an anci ...

  7. UVA 10192 Vacation

    裸最长公共子序列 #include<time.h> #include <cstdio> #include <iostream> #include<algori ...

  8. LightOJ1126 Building Twin Towers(DP)

    题目 Source http://www.lightoj.com/volume_showproblem.php?problem=1126 Description Professor Sofdor Al ...

  9. The Twin Towers zoj2059 DP

    The Twin Towers Time Limit: 2 Seconds      Memory Limit: 65536 KB Twin towers we see you standing ta ...

随机推荐

  1. bzoj1861 [Zjoi2006]Book 书架 splay

    小T有一个很大的书柜.这个书柜的构造有些独特,即书柜里的书是从上至下堆放成一列.她用1到n的正整数给每本书都编了号. 小T在看书的时候,每次取出一本书,看完后放回书柜然后再拿下一本.由于这些书太有吸引 ...

  2. css3文件树

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  3. How to duplicate a UIButton in Objective C?

    http://stackoverflow.com/questions/1092875/how-to-duplicate-a-uibutton-in-objective-c 1down vote To ...

  4. 非常好!!!Linux源代码阅读——内核引导【转】

    Linux源代码阅读——内核引导 转自:http://home.ustc.edu.cn/~boj/courses/linux_kernel/1_boot.html 目录 Linux 引导过程综述 BI ...

  5. fork+exec 与system,popen区别

    1.fork + exec fork用来创建一个子进程.一个程序一调用fork函数,系统就为一个新的进程准备了前述三个段,首先,系统让新的进程与旧的进程使用同一个代码段,因为它们的程序还是相同的,对于 ...

  6. 在Visual Studio 2013 上开发Node.js程序

    [题外话] 最近准备用Node.js做些东西,于是找找看能否有Visual Studio上的插件以方便开发.结果还真找到了一个,来自微软的Node.js Tools for Visual Studio ...

  7. 携程ELK

    http://www.360doc.com/content/15/1203/00/26186435_517522477.shtml

  8. 获取父窗口iframe方法

    在页面中,有个iframe,基于这个iframe,弹出了个窗口,这个窗口在关闭的时候需要操作iframe里的元素. 做法是 window.top.document.getElementById(&qu ...

  9. selenium IE自动化问题汇总

    驱动下载:http://selenium-release.storage.googleapis.com/index.html 没有修改IE的保护模式设置导致,通常看到报错信息如下: selenium. ...

  10. 【BZOJ4458】GTY的OJ

    题面 Description 身为IOI金牌的gtyzs有自己的一个OJ,名曰GOJ.GOJ上的题目可谓是高质量而又经典,他在他的OJ里面定义了一个树形的分类目录,且两个相同级别的目录是不会重叠的.比 ...