BNUOJ 4215 最长公共连续子序列
2014-07-10 14:54
176 查看
[b]最长公共连续子序列[/b]
Time Limit: 1000msMemory Limit: 65536KB
64-bit integer IO format: %lld Java class name: Main
给你两个序列S1和S2,长度分别是L1,L2 (1 <= L1 , L2 <= 180).
写一个程序找出最长的连续公共子序列。
连续子序列定义为序列中连续的一个片段。例如序列"1 2 3"的子串有空串,"1","2","3","1 2","2 3","1 2 3"。
Input
第1行:两个整数L1,L2,以一个空格隔开。第2行到第L1+1行:每行一个整数,第i+1行给出S1中的第i个数。
第L1+2行到第L1+L2+1行:每行一个整数,第L1+i+1行给出S1中的第i个数。
Output
一个整数,给出S1和S2的最长连续子序列的长度Sample Input
10 12 1 1 1 3 2 3 3 3 4 5 1 1 1 1 3 2 3 3 4 4 5 -8
Sample Output
7
Source
第八届北京师范大学程序设计竞赛热身赛第四场#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <vector> #include <climits> #include <algorithm> #include <cmath> #define LL long long using namespace std; int a[200],b[200],dp[200][200]; int main(){ int n,m,i,j,ans; while(~scanf("%d %d",&n,&m)){ for(i = 1; i <= n; i++) scanf("%d",a+i); for(j = 1; j <= m; j++) scanf("%d",b+j); memset(dp,0,sizeof(dp)); for(ans = 0,i = 1; i <= n; i++){ for(j = 1; j <= m; j++){ if(a[i] == b[j]){ dp[i][j] = dp[i-1][j-1]+1; } if(dp[i][j] > ans) ans = dp[i][j]; } } printf("%d\n",ans); } return 0; }
View Code
相关文章推荐
- 个人模板 最长公共连续子序列
- [笔试]阿里笔试-最长公共连续子序列
- hdu5902 GCD is Funny(错) && hdu5904 LCIS(最长公共连续上升子序列)
- 【100题】最长公共子串--非连续子串----动态规划
- URAL 1517. Freedom of choice(后缀数组:最长公共连续子串)
- hdu 1423 Greatest Common Increasing Subsequence 最长公共上升子序列
- 5-1 最长连续递增子序列
- 最长公共上升子序列 LCIS
- HDU 1003 Max Sum(最长连续子序列和)
- Codeforces 10D LCIS 求最长公共上升子序列及输出这个子序列 dp
- 湖南省第八届省赛 病毒 (最长公共上升子序列)
- ALBB 找公共最长连续字母序列的长度
- 最大子序列最长递增子序列最长公共子串最长公共子序列
- HDU 4512 吉哥系列故事――完美队形I(最长公共上升子序列)
- 最长公共上升子序列的DP解法及其优化
- 如何求最长连续公共子序列和最长连续子字符串
- 最长公共连续子串和最长连续公共子序列
- 最长公共上升子序列算法
- hdu 1423 最长公共递增子序列
- 动态规划之最大公共序列+最长上升子序列