link:http://poj.org/problem?id=1458

最基础的那种

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
const int dir[][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
using namespace std;
int sad[][];char apple[],pear[];
int main(void)
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin );
#endif // ONLINE_JUDGE
// while (gets(apple)!=NULL && gets(pear)!=NULL)
while (~scanf("%s%s",apple,pear))
{
memset(sad,,sizeof(sad));
int lena=strlen(apple),lenp=strlen(pear);
for(int i=;i<lena;++i)
{
for(int j=;j<lenp;++j)
{
if(apple[i]==pear[j]) sad[i+][j+]=sad[i][j]+;
else sad[i+][j+]=max(sad[i][j+],sad[i+][j]);
}
}
printf("%d\n",sad[lena][lenp]);
} return ;
}

开始把sad数组类型写成char型了,样例竟然也会对。

poj1458 Common Subsequence ——最长公共子序列的更多相关文章

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

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

  2. C++版 - Lintcode 77-Longest Common Subsequence最长公共子序列(LCS) - 题解

    版权声明:本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C++版 - L ...

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

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

  4. HDU 1159 Common Subsequence 最长公共子序列

    HDU 1159 Common Subsequence 最长公共子序列 题意 给你两个字符串,求出这两个字符串的最长公共子序列,这里的子序列不一定是连续的,只要满足前后关系就可以. 解题思路 这个当然 ...

  5. LCS(Longest Common Subsequence 最长公共子序列)

    最长公共子序列 英文缩写为LCS(Longest Common Subsequence).其定义是,一个序列 S ,如果分别是两个或多个已知序列的子序列,且是所有符合此条件序列中最长的,则 S 称为已 ...

  6. hdu 1159 Common Subsequence(最长公共子序列 DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...

  7. LCS修改版(Longest Common Subsequence 最长公共子序列)

    题目描述 作为一名情报局特工,Nova君(2号)有着特殊的传达情报的技巧.为了避免被窃取情报,每次传达时,他都会发出两句旁人看来意义不明话,实际上暗号已经暗含其中.解密的方法很简单,分别从两句话里删掉 ...

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

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

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

    最长公共子序列(LCS)是一个在一个序列集合中(通常为两个序列)用来查找所有序列中最长子序列的问题.这与查找最长公共子串的问题不同的地方是:子序列不需要在原序列中占用连续的位置 .最长公共子序列问题是 ...

随机推荐

  1. 转 猫都能学会的Unity3D Shader入门指南(二)

    猫都能学会的Unity3D Shader入门指南(二) 关于本系列 这是Unity3D Shader入门指南系列的第二篇,本系列面向的对象是新接触Shader开发的Unity3D使用者,因为我本身自己 ...

  2. python打怪之路【第二篇】:ImportError: No module named setuptools

    在python安装第三方模块时出现如下错误: python错误:ImportError: No module named setuptools这句错误提示的表面意思是:没有setuptools的模块, ...

  3. 获得省市 json 后台代码

    string connString = ConfigurationManager.ConnectionStrings["connStr"].ToString(); SqlConne ...

  4. easyui combotree 只能选择子节点

    //区号只能选子节点 $("#quhao").combotree({ onBeforeSelect: function (node) { //返回树对象 var tree = $( ...

  5. 基于讯为4412开发板的Android开发流程

    讯为4412开发板  使用三星2410芯片,基于arm9架构,由于自己电脑硬件的局限,只能跑Android4.0.3系统. 1.Uboot这个直接使用官方镜像烧写就可以了,一般情况不用去重复烧写. 略 ...

  6. angularjs简述

    1.MVC设计模式 MVC 是一种使用 MVC(Model View Controller 模型-视图-控制器)设计创建 Web 应用程序的模式 Model(模型)表示应用程序核心(比如数据库记录列表 ...

  7. gz

    不准备的话,是真的会滚粗的. leetcode  还是重新做起来叭. 那么就开始咯 8.22 leetcode 144 Binary Tree Preorder Traversal 二叉树的前序遍历 ...

  8. SQLServer更新语句要注意

    在SQLServer中 update语句中对于表不能使用别名 eg:update table a set a.column="" where ... 这样在SQLServer中是不 ...

  9. NetworkComms V3 之发送UDP广播消息

    NetworkComms网络通信框架序言 NetworkComms通信框架,是一款来自英国的c#语言编写的通信框架,历时6年研发,成熟稳定,性能可靠. NetworkComms v3目前只支持基本的U ...

  10. HTTP 错误 500.23 - Internal Server Error 解决方法

    分析原因:在安装完成后IIS已经支持ASP和ASP.NET 2.0,需要注意的是.NET站点的应用程序池应选用Classic .NET AppPool,而不能用默认的DefaultAppPool,否则 ...