题意:略

求最长公共子串

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<string>
  4. using namespace std;
  5. int dp[500][500];
  6. int max(int a,int b)
  7. {
  8. return a>b?a:b;
  9. }
  10. int main()
  11. {
  12. int i,j,a,b;
  13. char s1[400],s2[400];
  14. while(scanf("%s%s",s1,s2)!=EOF)
  15. {
  16. memset(dp,0,sizeof(dp));
  17. a=strlen(s1);
  18. b=strlen(s2);
  19. for(i=1;i<=a;i++)
  20. {
  21. for(j=1;j<=b;j++)
  22. {
  23. if(s1[i-1]==s2[j-1])
  24. {
  25. dp[i][j]=dp[i-1][j-1]+1;
  26. }
  27. else
  28. {
  29. dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
  30. }
  31. }
  32. }
  33. printf("%d\n",dp[a][b]);
  34. }
  35. return 0;
  36. }

poj 1458 Common Subsequence_最长公共子串的更多相关文章

  1. POJ 1458 Common Subsequence(最长公共子序列LCS)

    POJ1458 Common Subsequence(最长公共子序列LCS) http://poj.org/problem?id=1458 题意: 给你两个字符串, 要你求出两个字符串的最长公共子序列 ...

  2. POJ 1458 Common Subsequence 最长公共子序列 LCS

    LCS #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> ...

  3. POJ 1458 Common Subsequence 最长公共子序列

    题目大意:求两个字符串的最长公共子序列 题目思路:dp[i][j] 表示第一个字符串前i位 和 第二个字符串前j位的最长公共子序列 #include<stdio.h> #include&l ...

  4. lintcode 77.Longest Common Subsequence(最长公共子序列)、79. Longest Common Substring(最长公共子串)

    Longest Common Subsequence最长公共子序列: 每个dp位置表示的是第i.j个字母的最长公共子序列 class Solution { public: int findLength ...

  5. POJ 3294 Life Forms [最长公共子串加强版 后缀数组 && 二分]

    题目:http://poj.org/problem?id=3294 Life Forms Time Limit: 5000MS   Memory Limit: 65536K Total Submiss ...

  6. POJ 2217 (后缀数组+最长公共子串)

    题目链接: http://poj.org/problem?id=2217 题目大意: 求两个串的最长公共子串,注意子串是连续的,而子序列可以不连续. 解题思路: 后缀数组解法是这类问题的模板解法. 对 ...

  7. [poj 2274]后缀数组+最长公共子串

    题目链接:http://poj.org/problem?id=2774 后缀数组真的太强大了,原本dp是O(nm)的复杂度,在这里只需要O(n+m). 做法:将两个串中间夹一个未出现过的字符接起来,然 ...

  8. PKU 1458 Common Subsequence(最长公共子序列,dp,简单)

    题目 同:ZJU 1733,HDU 1159 #include <stdio.h> #include <string.h> #include <algorithm> ...

  9. POJ 1458 Common Subsequence(LCS最长公共子序列)

    POJ 1458 Common Subsequence(LCS最长公共子序列)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?c ...

随机推荐

  1. List<T>类

    List<T>类是ArrayList的泛型等效版本,两者功能相似.它实现了6个接口,实际上市对应的3对. 1.IEnumerable<T>和IEnumerable 2.ICol ...

  2. 【原创整理,基于JavaScript的创建对象方式的集锦】

    以下4种方式,是我在项目中最常见的JavaScript的面向对象的方式的开发. 测试一般在微软的工具:http://www.typescriptlang.org/Playground 进行测试,或者使 ...

  3. PYCURL ERROR 6 - “Couldn't resolve host 'mirrorlist.centos.org'”

    在虚拟机上安装的CentOS,估计是网络配置问题,导致yum update和yum install之类的功能的用不了.出现标题上面的错误. ifdown [network_adapter] ifup ...

  4. 用B-树实现虚拟图书管理系统

    学校数据结构的课程实验之一. 用到的数据结构:B-树 基本功能:对虚拟书库的图书进行查看.增加.删除.修改. 主函数: #include <iostream> #include " ...

  5. openstack vm image

    1,openstack 基于iso生成镜像

  6. apache FtpServer整合spring逻辑处理

    上面我们的部署工作完成了,那么文件上传下载后,ftpserver会自动相应我们的上传下载操作,也就是说ftpServer服务器会得到触发,那么我们如果要得到文件的一些信息,比如说文件的路径.大小.类型 ...

  7. 【转】linux环境变量设置

    1. 显示环境变量HOME $ echo $HOME /home/terry 2. 设置一个新的环境变量WELCOME $ export WELCOME="Hello!" $ ec ...

  8. Back to Underworld(搜索)

    Back to Underworld Time Limit:4000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Su ...

  9. ubuntu系统分区方案

    一.各文件及文件夹的定义 /bin:bin是binary(二进制)的缩写.存放必要的命令 存放增加的用户程序. /bin分区,存放标准系统实用程序./boot:这里存放的是启动LINUX时使用的一些核 ...

  10. [KMP求最小循环节][HDU3746][Cyclic Nacklace]

    题意 给你个字符串,问在字符串末尾还要添加几个字符,使得字符串循环2次以上. 解法 无论这个串是不是循环串 i-next[i] 都能求出它的最小循环节 代码: /* 思路:kmp+字符串的最小循环节问 ...