#HDU 1159 Common Subsequence
来源:互联网 发布:微信轰天雷炸群软件 编辑:程序博客网 时间:2024/06/17 03:23
Common Subsequence
题意&分析:
对于给定的两个字符串,求最长公共子序列。直接用LCS算法,一个DP。
代码如下:
#include <bits/stdc++.h>#define INF 0x3f3f3f3f#define TEST cout<<"stop here"<<endl using namespace std;typedef long long ll;const ll mod = 1e9 + 7;int dp[1010][1010];int main(){ std::ios::sync_with_stdio(false); std::cin.tie(0); string s1,s2; while(cin>> s1 >> s2){ memset(dp,0,sizeof(0)); int len1 = s1.size(); int len2 = s2.size();//cout<<len1<<" "<< len2<<endl; for(int i=1;s1[i-1];i++){ for(int j=1;s2[j-1];j++){ if(s1[i-1] == s2[j-1]) dp[i][j] = dp[i-1][j-1] + 1; else dp[i][j] = max(dp[i-1][j],dp[i][j-1]); } } cout<< dp[len1][len2] <<endl; } return 0;}
参考资料:
奇妙的LCS算法妙解 传送门
阅读全文
0 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
- MySQL详解--锁机制
- Java类的设计----方法的重写、覆盖
- 操作系统的页式管理
- 要素内部几何空间查询
- 【NOI2015模拟8.17】最短路(shortest)
- #HDU 1159 Common Subsequence
- JAVA-IO(3)操作简介
- hdu6070
- HDU 4609 3-idiots
- JS基础--常用对象
- Java8新时间与日期API—本地时间与时间戳
- 最长递增子序列
- windows 无法连接xxxxx (无法连接无线路由器)
- 学习笔记--操作系统的知识点的概括(思维导图形式)