链接: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. Educational Codeforces Round 2 B. Queries about less or equal elements

    打开题目连接 题意:给2个数组(无序的)啊a,b,判断b数组中的每一个元素大于a数组中个数. ACcode: #include <iostream> #include <vector ...

  2. [USACO06NOV]玉米田Corn Fields (状压$dp$)

    题目链接 Solution 状压 \(dp\) . \(f[i][j][k]\) 代表前 \(i\) 列中 , 已经安置 \(j\) 块草皮,且最后一位状态为 \(k\) . 同时多记录一个每一列中的 ...

  3. 用类加载器的5种方式读取.properties文件

    用类加载器的5中形式读取.properties文件(这个.properties文件一般放在src的下面) 用类加载器进行读取:这里采取先向大家讲读取类加载器的几种方法:然后写一个例子把几种方法融进去, ...

  4. Git基本用法简介

    一.           git和svn的主要区别 git是一个分布式的版本控制工具,而svn是一个集中式版本控制工具. 二.           git工具安装 首先下载git:https://gi ...

  5. java io 网络编程 高性能NIO

    很久没写了,一是觉得这后台不怎么方便,二是 写的时候突然觉得没兴趣了. 还好,今天突然想记一下,那就随便写吧.  1.一开始还是放几个连接.  什么是 同步,异步,阻塞,非阻塞 : http://bl ...

  6. vue elementui 递归 sidebar可伸缩侧边栏

    最近在学习vue 做了一个可伸缩的 侧边栏 记录下 在很多管理系统都用到 管理系统一般都长的差不多 首先是收起时候 展开时候 首先是新建一个Layout.vue <template> &l ...

  7. 【leetcode】500. Keyboard Row

    问题描述: Given a List of words, return the words that can be typed using letters of alphabet on only on ...

  8. (3) python--matplotlib

    (一)1.如何绘制散点图 import numpy as np import matplotlib.pyplot as plt # 如何绘制散点图 # 先随机生成数据 x = np.array(ran ...

  9. Selenium2+python自动化7-xpath定位【转载】

    前言 在上一篇简单的介绍了用工具查看目标元素的xpath地址,工具查看比较死板,不够灵活,有时候直接复制粘贴会定位不到.这个时候就需要自己手动的去写xpath了,这一篇详细讲解xpath的一些语法. ...

  10. 通过过滤器和增强request对象解决get提交请求服务器端乱码。

    1.表单用get方式提交 <%@ page language="java" contentType="text/html; charset=UTF-8" ...