poj1458
来源:互联网 发布:加盟农村淘宝怎么盈利 编辑:程序博客网 时间:2024/06/16 18:43
题意:求两个字符串的最长子序列
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<cstring>using namespace std;int dp[1000][1000];char s1[1000],s2[1000];int len1,len2;//int LCS(int ,int);int max(int a,int b, int c){ if(a>=b && a>=c) return a; if(b>=a && b>=c) return b; return c;}int main(){ int i,j; while(scanf("%s %s",s1,s2)!=EOF) { len1=strlen(s1); len2=strlen(s2); memset(dp,0,sizeof(dp)); for(i=1;i<=len1;i++) { for(j=1;j<=len2;j++) { if(s1[i-1]==s2[j-1]) dp[i][j]=max(dp[i-1][j-1]+1,dp[i-1][j],dp[i][j-1]); else dp[i][j]=max(dp[i-1][j-1],dp[i-1][j],dp[i][j-1]); } } printf("%d\n",dp[len1][len2]); } return 0;}/*int LCS(int i,int j){ if(i>=len1 || j>=len2) return 0; if(s1[i]==s2[j]) return 1+LCS(i+1,j+1); else return LCS(i+1,j)>LCS(i,j+1)? LCS(i+1,j):LCS(i,j+1);}*///用的递归
0 0
- poj1458
- POJ1458
- poj1458
- poj1458
- poj1458
- poj1458
- poj1458
- poj1458
- poj1458
- poj1458
- POj1458
- POJ1458
- poj1458
- poj1458
- poj1458
- POJ1458 LCS
- poj1458 dp
- 【DP】poj1458
- Linux查看CPU和内存使用情况
- C语言学习笔记:内存分配
- 快速排序
- 移动端前端JS事件相关
- 报表数据源的多重判断
- poj1458
- 代码托管:git
- 如何实现全国全网验证码类短信接口的调用?
- Android Animation学习笔记
- 【Flume】flume的自定义组件如何才能被flume的httpmetricsServer监控起来呢?
- javaBean总结
- 【.Net码农】关于vs2005、vs2008和vs2010项目互转的总结
- IntentFilter
- Solaris 10 配置DHCP服务