九度oj-1042-Coincidence
来源:互联网 发布:查看iptables开放端口 编辑:程序博客网 时间:2024/05/20 03:41
- 题目描述:
Find a longest common subsequence of two strings.
- 输入:
First and second line of each input case contain two strings of lowercase character a…z. There are no spaces before, inside or after the strings. Lengths of strings do not exceed 100.
- 输出:
For each case, output k – the length of a longest common subsequence in one line.
- 样例输入:
abcdcxbydz
- 样例输出:
2
- 来源:
- 2008年上海交通大学计算机研究生机试真
#include<iostream>#include<cstring>#include<algorithm>using namespace std;int a[103][103];string b,c;int main(){ int i,j; while(cin>>b>>c) { int bb=b.length(); int cc=c.length(); memset(a,0,sizeof(a)); if(b[0]==c[0]) a[0][0]=1; for(i=1;i<bb;i++) if(b[i]==c[0]) a[i][0]=1; else a[i][0]=a[i-1][0]; for(j=1;j<cc;j++) if(c[j]==b[0]) a[0][j]=1; else a[0][j]=a[0][j-1]; for(i=1;i<bb;i++) for(j=1;j<cc;j++) { if(b[i]==c[j]) a[i][j]=a[i-1][j-1]+1; else a[i][j]=max(a[i-1][j],a[i][j-1]); } cout<<a[bb-1][cc-1]<<endl; } return 0;}
0 0
- 九度oj-1042-Coincidence
- [九度OJ]1042Coincidence
- 九度oj 题目1042:Coincidence
- 九度1042:Coincidence
- 九度[1042]-Coincidence
- 九度 oj 题目1042:Coincidence (LCS)
- 九度OJ-1042:Coincidence(最长公共子序列)
- 九度OJ 1042 Coincidence -- 动态规划(最长公共子序列)
- 九度OJ 1042 Coincidence (动态规划求最长公共子序列)
- 九度OJ 1042:Coincidence(公共子序列) (DP)
- 九度oj 1042
- 九度OJ 1042
- 题目1042:Coincidence
- 题目1042:Coincidence
- 题目1042:Coincidence
- 题目1042:Coincidence
- Coincidence
- Coincidence
- source insight 注册码
- 没有躲过的坑--string中的c_str()陷阱
- 数组
- 利用Aspose.Word控件实现Word文档的操作
- 进程间通信 SharedMemory 最后例子没看明白
- 九度oj-1042-Coincidence
- (imooc)sublime中的命令模式
- HDU3549 网络流入门题(Dinic)
- Leetcode Linked List Cycle
- toolButton
- javax.swing.Timer 的用法例程
- seajs模块加载
- Maven导入本地jar包
- 为activity增加左右手势识别(scrollview,gridview,listview适用)