虽然以前可能接触过最长公共子序列,但是正规的写应该还是第一次吧。

  直接贴代码就好了吧:

 #include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
const int N = + ; char a[N],b[N];
int dp[N][N]; int main()
{
while(scanf("%s%s",a+,b+) == )
{
int n = strlen(a+);
int m = strlen(b+);
memset(dp,,sizeof dp);
for(int i=;i<=n;i++)
{
for(int j=;j<=m;j++)
{
if(a[i] == b[j]) dp[i][j] = dp[i-][j-] + ;
else dp[i][j] = max(dp[i][j-], dp[i-][j]);
}
}
printf("%d\n",dp[n][m]);
}
}

poj 1458 Common Subsequence ——(LCS)的更多相关文章

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

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

  2. POJ 1458 Common Subsequence (动态规划)

    题目传送门 POJ 1458 Description A subsequence of a given sequence is the given sequence with some element ...

  3. POJ 1458 Common Subsequence (DP+LCS,最长公共子序列)

    题意:给定两个字符串,让你找出它们之间最长公共子序列(LCS)的长度. 析:很明显是个DP,就是LCS,一点都没变.设两个序列分别为,A1,A2,...和B1,B2..,d(i, j)表示两个字符串L ...

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

    题目链接Time Limit: 1000MS Memory Limit: 10000K Total Submissions: Accepted: Description A subsequence o ...

  5. Longest common subsequence(LCS)

    问题 说明该问题在生物学中的实际意义 Biological applications often need to compare the DNA of two (or more) different ...

  6. hdu 1159 Common Subsequence(LCS)

    Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. ZOJ 1733 Common Subsequence(LCS)

    Common Subsequence Time Limit: 2 Seconds      Memory Limit: 65536 KB A subsequence of a given sequen ...

  8. poj 1458 Common Subsequence【LCS】

    Common Subsequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 43132   Accepted: 17 ...

  9. poj 1458 Common Subsequence(dp)

    Common Subsequence Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 46630   Accepted: 19 ...

随机推荐

  1. liteide

    /liteide$ bin/liteide Cannot mix incompatible Qt library (version 0x40806) with this library (versio ...

  2. rabbitMQ 安装,基于Windows环境

    参考文章:https://www.cnblogs.com/ericli-ericli/p/5902270.htmlRabbit MQ 是建立在Erlang OTP平台上,安装前需先安装Erlang.h ...

  3. js移动端回退监听 popstate

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. 关于vue.js的部分总结

    1.MVVM和MVC的区别: MVVM:是Model-View-ViewModel的简写,即模型-视图-视图模型 模型:后端传递的数据 试图:所看到的页面 视图模型:mvvm模式的核心,它是连接vie ...

  5. nginx的so_keepalive和timeout相关小计

    KeepAlive 这里的keepalive是TCP的探活机制: [root@ ~]# sysctl -a |grep tcp_keepalive net.ipv4.tcp_keepalive_tim ...

  6. 负载均衡之haproxy负载均衡算法及haproxy的工作模式

    haproxy负载均衡的算法有如下7种: .roundrobin : 基于权重轮循. static-rr : 基于权重轮循.静态算法,运行时改变无法生效 source : 基于请求源IP的算法.对请求 ...

  7. MySQL sql_mode 说明(及处理一起 sql_mode 引发的问题)

    1. MySQL莫名变成了 Strict SQL Mode 最近测试组那边反应数据库部分写入失败,app层提示是插入成功,但表里面里面没有产生数据,而两个写入操作的另外一个表有数据.因为 insert ...

  8. Image Processing and Analysis_21_Scale Space:Feature Detection with Automatic Scale Selection——1998

    此主要讨论图像处理与分析.虽然计算机视觉部分的有些内容比如特 征提取等也可以归结到图像分析中来,但鉴于它们与计算机视觉的紧密联系,以 及它们的出处,没有把它们纳入到图像处理与分析中来.同样,这里面也有 ...

  9. 12_Azkaban案例实践5_Command操作Hive脚本任务

    HIVE脚本任务 hadoop fs -mkdir -p /aztest/hiveinput hadoop fs -put az.data /aztest/hiveinput/ l 创建job描述文件 ...

  10. YOLO---YOLOv3 with OpenCV 再使用

    YOLO---YOLOv3 with OpenCV 再使用YOLOv3 with OpenCV官网 @ https://github.com/JackKoLing/opencv_deeplearnin ...