hdu 1159 Common Subsequence
来源:互联网 发布:宿迁市12345网络问政 编辑:程序博客网 时间:2024/06/06 14:54
Common Subsequence
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 76 Accepted Submission(s) : 35
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
The program input is from a text file. Each data set in the file contains two strings representing the given sequences. The sequences are separated by any number of white spaces. The input data are correct. For each set of data the program prints on the standard output the length of the maximum-length common subsequence from the beginning of a separate line.
Sample Input
abcfbc abfcabprogramming contest abcd mnp
Sample Output
420
很正常的求最长公共子序列的最长长度。
#include<iostream>#include<cmath>#include<algorithm>#include<iomanip>#include<cstring>#include<cstdio>#include<queue>using namespace std;int n,m;int ans;char a[111111];char b[111111];int dp[1111][1111];int main(){ while(cin>>a>>b) { int l1=strlen(a); int l2=strlen(b); for(int i=l1;i>=1;i--) a[i]=a[i-1]; for(int i=l2;i>=1;i--) b[i]=b[i-1]; int l=max(l1,l2); memset(dp,0,sizeof(dp)); for(int i=0;i<=l;i++) { dp[0][i]=dp[i][0]=0; } for(int i=1;i<=l1;i++) for(int j=1;j<=l2;j++) { if(a[i]==b[j]) dp[i][j]=dp[i-1][j-1]+1; else { dp[i][j]=max(dp[i-1][j],dp[i][j-1]); } } cout<<dp[l1][l2]<<endl; } return 0;}
- hdu 1159 Common Subsequence
- HDU 1159 Common Subsequence
- HDU 1159 Common Subsequence
- hdu 1159 Common Subsequence
- HDU 1159 Common Subsequence
- HDU 1159 Common Subsequence
- hdu 1159 Common Subsequence
- hdu 1159 Common Subsequence
- hdu 1159 Common Subsequence
- Common Subsequence hdu 1159
- HDU 1159 Common Subsequence
- HDU 1159 Common Subsequence
- hdu 1159 Common Subsequence
- hdu 1159 Common Subsequence
- HDU 1159 Common Subsequence
- hdu 1159 Common Subsequence
- hdu 1159 Common Subsequence
- hdu 1159 Common Subsequence
- 【USACO】iCow播放器
- 为什么linux下多线程程序如此消耗虚拟内存
- 2017.07.15【NOIP提高组】模拟赛B组小结
- 8. String to Integer (atoi)
- 哇塞,不错的js--前端中的小算法
- hdu 1159 Common Subsequence
- 基本的Redis事务
- MYSQL 数据库内容出现中文乱码的解决办法
- 使用Windows Caffe 建立Qt工程 运行SSD(Single Shot MultiBox Detector)目标检测算法
- 博客每日访问量
- 图论500题
- jsp自动刷新
- 关于第一次使用redis的这件事
- css之负外边距