POJ 1458
#include <iostream>
#include <string>
#define MAXN 1000 using namespace std; string s_1;
string s_2;
void init();
int _m[MAXN][MAXN];
void fun_lcs();
int main()
{
// freopen("acm.acm","r",stdin);
while(cin>>s_1>>s_2)
{
init();
fun_lcs();
cout<<_m[s_1.length()][s_2.length()]<<endl;
} return ;
} void init()
{
int i;
int j;
_m[][] = ;
for(i = ; i < s_1.length(); ++ i)
{
_m[i+][] = ;
}
for(j = ; j < s_2.length(); ++ j)
{
_m[][j+] = ;
}
} void fun_lcs()
{
int i;
int j;
for(i = ; i < s_1.length(); ++ i)
{
for(j = ; j < s_2.length(); ++ j)
{
if(s_1[i] == s_2[j])
{
_m[i+][j+] = _m[i][j] + ;
}
else
{
if(_m[i+][j] > _m[i][j+])
{
_m[i+][j+] = _m[i+][j];
}
else
{
_m[i+][j+] = _m[i][j+];
}
}
}
}
}
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com
POJ 1458的更多相关文章
- LCS POJ 1458 Common Subsequence
题目传送门 题意:输出两字符串的最长公共子序列长度 分析:LCS(Longest Common Subsequence)裸题.状态转移方程:dp[i+1][j+1] = dp[i][j] + 1; ( ...
- POJ 1458 Common Subsequence(LCS最长公共子序列)
POJ 1458 Common Subsequence(LCS最长公共子序列)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?c ...
- POJ 1458 最长公共子序列(dp)
POJ 1458 最长公共子序列 题目大意:给出两个字符串,求出这样的一 个最长的公共子序列的长度:子序列 中的每个字符都能在两个原串中找到, 而且每个字符的先后顺序和原串中的 先后顺序一致. Sam ...
- POJ 1458 Common Subsequence (动态规划)
题目传送门 POJ 1458 Description A subsequence of a given sequence is the given sequence with some element ...
- POJ 1458 1159
http://poj.org/problem?id=1458 一道容易的DP,求最长公共子序列的 dp[i][j],代表str1中的第i个字母和str2中的第j个字母的最多的公共字母数 #includ ...
- OpenJudge/Poj 1458 Common Subsequence
1.链接地址: http://poj.org/problem?id=1458 http://bailian.openjudge.cn/practice/1458/ 2.题目: Common Subse ...
- poj 1458 Common Subsequence(区间dp)
题目链接:http://poj.org/problem?id=1458 思路分析:经典的最长公共子序列问题(longest-common-subsequence proble),使用动态规划解题. 1 ...
- (最长公共子序列 暴力) Common Subsequence (poj 1458)
http://poj.org/problem?id=1458 Description A subsequence of a given sequence is the given sequence w ...
- POJ 1458 Common Subsequence(最长公共子序列LCS)
POJ1458 Common Subsequence(最长公共子序列LCS) http://poj.org/problem?id=1458 题意: 给你两个字符串, 要你求出两个字符串的最长公共子序列 ...
- POJ 1458 Common Subsequence DP
http://poj.org/problem?id=1458 用dp[i][j]表示处理到第1个字符的第i个,第二个字符的第j个时的最长LCS. 1.如果str[i] == sub[j],那么LCS长 ...
随机推荐
- CodeForces 569A 第八次比赛 C题
Description Little Lesha loves listening to music via his smartphone. But the smartphone doesn't hav ...
- asp.net实现手机号码归属地查询
protected void Button1_Click(object sender, EventArgs e) { if (Regex.IsMatch(TextB ...
- func_num_args(),func_get_arg(),func_get_args()
<?php function testFunction1(){ return func_num_args(); } function testFunction2(){ return func_g ...
- 【坑】执行Consumer的时候发生java.net.UnknownHostException错误
[时间]: 2016/4/8 17:30 [问题]: kafka执行Consumer实例的时候,发生了一下错误. kafka配置文件server.properties如下: zookeeper配置文件 ...
- 插入排序 & 快速排序
2.1 插入排序: 接口定义: int insert_sort(void* data, int size, int esize, int (*compare)(const void* key1, co ...
- 使用VBA实现Excel自杀功能
曾经看到过一个“Excel-Home”出品的“关于Excel自杀功能”的视频教程,经认真学习后,我写下了自己的代码,分享于此. 实现思路: 使用VBA创建一个隐藏的名称,记录当前工作簿打开的次数,如果 ...
- 团队作业index
<head><meta http-equiv="Content-Type" content="text/html; charset=gb2312&quo ...
- js判断浏览器滚动条是否拉到底
$(window).scroll(function(){ // 当滚动到最底部以上n像素时, 加载新内容 if ($(document).height() - $(this).scrollTop() ...
- hdu 3879 Base Station 最大权闭合图
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3879 A famous mobile communication company is plannin ...
- Hdu 1009 FatMouse' Trade 分类: Translation Mode 2014-08-04 14:07 74人阅读 评论(0) 收藏
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...