POJ 1458 Common Subsequence - from lanshui_Yang
来源:互联网 发布:centos7源码编译 lnmp 编辑:程序博客网 时间:2024/05/19 23:16
题目大意:给你连个字符串A 和 B , 让你求A 和 B 的最长公共子序列。
解题思路:此题属简单的DP 问题, 具体讲解推荐以下博客:
http://blog.csdn.net/yysdsyl/article/details/4226630
我的代码如下:
#include<iostream>#include<cstring>#include<cstdio>#include<string>#include<algorithm>#include<cmath>using namespace std ;const int MAXN = 1e4 + 5 ;char x[MAXN] ;char y[MAXN] ;int L[MAXN][MAXN] ;void solve(){ int lenx = strlen(x) ; int leny = strlen(y) ; int i , j ; for(i = 0 ; i <= lenx ; i ++) L[i][0] = 0 ; for(j = 0 ; j <= leny ; j ++) L[0][j] = 0 ; for(i = 1 ; i <= lenx ; i ++) { for(j = 1 ; j <= leny ; j ++) { if(x[i - 1] == y[j - 1]) { L[i][j] = L[i - 1][j - 1] + 1 ; } else { L[i][j] = max(L[i - 1][j] , L[i][j - 1]) ; } } } printf("%d\n" , L[lenx][leny]) ;}int main(){ while (scanf("%s" , x) != EOF) { scanf("%s" , y) ; solve() ; } return 0 ;}
- POJ 1458 Common Subsequence - from lanshui_Yang
- POJ 2533 Longest Ordered Subsequence - from lanshui_Yang
- Common Subsequence--poj--1458
- poj 1458 Common Subsequence
- poj 1458 Common Subsequence
- Poj 1458 Common Subsequence
- POJ 1458 Common Subsequence
- poj 1458 Common Subsequence
- poj 1458 Common Subsequence
- POJ 1458 Common Subsequence
- poj 1458 Common Subsequence
- POJ-1458-Common Subsequence
- POJ 1458 Common Subsequence
- poj 1458 Common Subsequence
- POJ 1458 Common Subsequence
- poj 1458 Common Subsequence
- POJ 1458 Common Subsequence
- POJ 1458 Common Subsequence
- Java NIO框架Mina、Netty、Grizzly介绍与对比
- C++ Virtual详解
- IDEA启动tomcat报Unable to ping server at localhost:1099 解决
- 正则表达式30分钟入门教程
- 【PAT】1006. Sign In and Sign Out (25)
- POJ 1458 Common Subsequence - from lanshui_Yang
- 分布式系统的计算部分的常见优化思路
- Android表达式计算器
- C#中public、private、protected、internal、protected internal
- ios错误日志分析
- .Net 分布式缓存
- Javascript表格翻页效果
- ubuntu samba服务器多用户配置
- C和C++的区别