poj 1458 Common Subsequence_最长公共子串
题意:略
求最长公共子串
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int dp[500][500];
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int i,j,a,b;
char s1[400],s2[400];
while(scanf("%s%s",s1,s2)!=EOF)
{
memset(dp,0,sizeof(dp));
a=strlen(s1);
b=strlen(s2);
for(i=1;i<=a;i++)
{
for(j=1;j<=b;j++)
{
if(s1[i-1]==s2[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("%d\n",dp[a][b]);
}
return 0;
}
poj 1458 Common Subsequence_最长公共子串的更多相关文章
- POJ 1458 Common Subsequence(最长公共子序列LCS)
POJ1458 Common Subsequence(最长公共子序列LCS) http://poj.org/problem?id=1458 题意: 给你两个字符串, 要你求出两个字符串的最长公共子序列 ...
- POJ 1458 Common Subsequence 最长公共子序列 LCS
LCS #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> ...
- POJ 1458 Common Subsequence 最长公共子序列
题目大意:求两个字符串的最长公共子序列 题目思路:dp[i][j] 表示第一个字符串前i位 和 第二个字符串前j位的最长公共子序列 #include<stdio.h> #include&l ...
- lintcode 77.Longest Common Subsequence(最长公共子序列)、79. Longest Common Substring(最长公共子串)
Longest Common Subsequence最长公共子序列: 每个dp位置表示的是第i.j个字母的最长公共子序列 class Solution { public: int findLength ...
- POJ 3294 Life Forms [最长公共子串加强版 后缀数组 && 二分]
题目:http://poj.org/problem?id=3294 Life Forms Time Limit: 5000MS Memory Limit: 65536K Total Submiss ...
- POJ 2217 (后缀数组+最长公共子串)
题目链接: http://poj.org/problem?id=2217 题目大意: 求两个串的最长公共子串,注意子串是连续的,而子序列可以不连续. 解题思路: 后缀数组解法是这类问题的模板解法. 对 ...
- [poj 2274]后缀数组+最长公共子串
题目链接:http://poj.org/problem?id=2774 后缀数组真的太强大了,原本dp是O(nm)的复杂度,在这里只需要O(n+m). 做法:将两个串中间夹一个未出现过的字符接起来,然 ...
- PKU 1458 Common Subsequence(最长公共子序列,dp,简单)
题目 同:ZJU 1733,HDU 1159 #include <stdio.h> #include <string.h> #include <algorithm> ...
- POJ 1458 Common Subsequence(LCS最长公共子序列)
POJ 1458 Common Subsequence(LCS最长公共子序列)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?c ...
随机推荐
- SQL Server 2008空间数据应用系列十:使用存储过程生成GeoRSS聚合空间信息
原文:SQL Server 2008空间数据应用系列十:使用存储过程生成GeoRSS聚合空间信息 友情提示,您阅读本篇博文的先决条件如下: 1.本文示例基于Microsoft SQL Server 2 ...
- 《how to design programs》第11章自然数
这章让我明白了原来自然数的定义本来就是个递归的过程. 我们通常用枚举的方式引出自然数的定义:0,1,2,3,等等(etc).最后的等等是什么意思?唯一能把等等从描述自然数的枚举方法中去除的方法是自引用 ...
- 添加python第三方插件时出现的问题
当我安装beautifulsoup4时出现了如下错误: Fatal error in launcher: Unable to create process using '""F:\ ...
- OpenWrt for vmware 从openwrt.org下载10.03.1 或是自己下载最新的源码进行编译生成x86 vmdk格式
1,直接从OpenWrt.org官网下载 http://downloads.openwrt.org/backfire/10.03.1/x86_generic/ 更新OpenWrt在线软件源 opkg ...
- Sonar入门(一):简介
什么是Sonar? Sonar是一个开源的代码质量管理平台.它能对代码进行如下7个维度的管理. 使用插件,它可以对20多种语言进行代码质量管理,这其中包括Java,C#,C/C++,PL/SQL等等. ...
- DOTween 模仿NGUI Tween
最近再做一个小的项目,只要使用的是DOTween 动画. 但是感到DOTween 在某些方面不如 NGUI的Twenn 比较好用 所以就模仿了一下 在此,请各位大神指点一下 public class ...
- Kyoya and Colored Balls(组合数)
Kyoya and Colored Balls time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 利用Inotify和Rsync将webproject文件自己主动同步到多台应用server
背景:须要搭建一套跟线上一模一样的环境,用来预公布,这是当中的web分发的一个小模块的实现过程. 1 工具以及环境简单介绍 1.1,Inotify工具 Inotify,它是一个内核用于通知用户空间程序 ...
- SyntaxError: Non-ASCII character '\xe2' in file 编码错误
Editing .py file in the Notepad: But when run in the PowerShell, I found the follwing error: It seem ...
- 【IOS学习基础】文件相关
一.沙盒(SandBox) 1.沙盒机制 1> 每个应用都有属于自己的存储空间,即沙盒. 2> 应用只能访问自己的沙盒,不可访问其他区域. 3> 如果应用需要进行文件操作,则必须将文 ...