Common Subsequence 1458 pku
2010-11-10 19:59
232 查看
#include<iostream>
#include<string.h>
using namespace std;
int exportMax(int a,int b)
{
return a>b? a:b;
}
int opt[1010][1010];
int main()
{
char str1[1010],str2[1010];
while(cin>>str1+1>>str2+1)
{
int len1=strlen(str1+1);
int len2=strlen(str2+1);
memset(opt,0,sizeof(opt));
for(int i=1;i<=len1;i++)
{
for(int j=1;j<=len2;j++)
{
if(str1[i]==str2[j])
{
opt[i][j]=opt[i-1][j-1]+1;
}
else
{
opt[i][j]=exportMax(opt[i-1][j],opt[i][j-1]);
}
}
}
cout<<opt[len1][len2]<<endl;
}
}
#include<string.h>
using namespace std;
int exportMax(int a,int b)
{
return a>b? a:b;
}
int opt[1010][1010];
int main()
{
char str1[1010],str2[1010];
while(cin>>str1+1>>str2+1)
{
int len1=strlen(str1+1);
int len2=strlen(str2+1);
memset(opt,0,sizeof(opt));
for(int i=1;i<=len1;i++)
{
for(int j=1;j<=len2;j++)
{
if(str1[i]==str2[j])
{
opt[i][j]=opt[i-1][j-1]+1;
}
else
{
opt[i][j]=exportMax(opt[i-1][j],opt[i][j-1]);
}
}
}
cout<<opt[len1][len2]<<endl;
}
}
相关文章推荐
- Pku acm 1458 Common Subsequence 动态规划解析
- Pku acm 1458 Common Subsequence 题意分析
- PKU-1458 Common Subsequence (最长公共子序列LCS)
- PKUOJ1458 Common Subsequence
- pku 1458 pku2250 pku3356 最长公共子序列
- Common Subsequence(PKU 1458)
- PKU 1458 HDOJ 1159 Common Subsequence
- pku1458-----Common Subsequence(经典动态规划题)
- PKU1458 最长公共字串 DP
- acm--pku--1458
- PKU1458 最长公共子序列
- pku 1458 Common Subsecquence(DP)
- PKU 1458 Common Subsequence(最长公共子序列,dp,简单)
- Pku acm 1458 Common Subsequence 动态规划题目解题报告(五)
- pku1179:Polygon
- poj1458 Common Subsequence
- pku 1691 Painting A Board 状态压缩dp
- pku3083Children of the Candy Corn-模拟+bfs
- [二分] PKU 1840 Eqs
- pku 2947 Widget Factory 高斯消元