hdu 1159 Common Subsequence(最长公共子序列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159
Common Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 37551 Accepted Submission(s): 17206
The program input is from a text file. Each data set in the file contains two strings representing the given sequences. The sequences are separated by any number of white spaces. The input data are correct. For each set of data the program prints on the standard output the length of the maximum-length common subsequence from the beginning of a separate line.
#include <stdio.h>
#include <string.h>
#include <algorithm> using namespace std; char x[], y[];
int b[][], c[][];
void LCS()
{
int i,j;
int len1 = strlen(x);
int len2 = strlen(y);
for (i = ; i <= len1; i ++) b[i][] = ;
for (j = ; j <= len2; j ++) b[][j] = ; for (i = ; i <= len1; i ++)
{
for (j = ; j <= len2; j ++)
{
if (x[i-] == y[j-])
b[i][j] = b[i-][j-] + ;
else
b[i][j] = max(b[i-][j],b[i][j-]);
}
}
printf("%d\n",b[len1][len2]);
} int main ()
{
while (scanf("%s%s",x,y)!=EOF)
{
LCS();
}
return ;
}
hdu 1159 Common Subsequence(最长公共子序列)的更多相关文章
- HDU 1159 Common Subsequence 最长公共子序列
HDU 1159 Common Subsequence 最长公共子序列 题意 给你两个字符串,求出这两个字符串的最长公共子序列,这里的子序列不一定是连续的,只要满足前后关系就可以. 解题思路 这个当然 ...
- hdu 1159 Common Subsequence(最长公共子序列 DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...
- C++版 - Lintcode 77-Longest Common Subsequence最长公共子序列(LCS) - 题解
版权声明:本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. C++版 - L ...
- POJ 1458 Common Subsequence(最长公共子序列LCS)
POJ1458 Common Subsequence(最长公共子序列LCS) http://poj.org/problem?id=1458 题意: 给你两个字符串, 要你求出两个字符串的最长公共子序列 ...
- lintcode 77.Longest Common Subsequence(最长公共子序列)、79. Longest Common Substring(最长公共子串)
Longest Common Subsequence最长公共子序列: 每个dp位置表示的是第i.j个字母的最长公共子序列 class Solution { public: int findLength ...
- LCS(Longest Common Subsequence 最长公共子序列)
最长公共子序列 英文缩写为LCS(Longest Common Subsequence).其定义是,一个序列 S ,如果分别是两个或多个已知序列的子序列,且是所有符合此条件序列中最长的,则 S 称为已 ...
- LCS修改版(Longest Common Subsequence 最长公共子序列)
题目描述 作为一名情报局特工,Nova君(2号)有着特殊的传达情报的技巧.为了避免被窃取情报,每次传达时,他都会发出两句旁人看来意义不明话,实际上暗号已经暗含其中.解密的方法很简单,分别从两句话里删掉 ...
- POJ 1458 Common Subsequence 最长公共子序列
题目大意:求两个字符串的最长公共子序列 题目思路:dp[i][j] 表示第一个字符串前i位 和 第二个字符串前j位的最长公共子序列 #include<stdio.h> #include&l ...
- LCS(Longest Common Subsequence)最长公共子序列
最长公共子序列(LCS)是一个在一个序列集合中(通常为两个序列)用来查找所有序列中最长子序列的问题.这与查找最长公共子串的问题不同的地方是:子序列不需要在原序列中占用连续的位置 .最长公共子序列问题是 ...
- PKU 1458 Common Subsequence(最长公共子序列,dp,简单)
题目 同:ZJU 1733,HDU 1159 #include <stdio.h> #include <string.h> #include <algorithm> ...
随机推荐
- 洛谷 P5249 [LnOI2019]加特林轮盘赌 题解【概率期望】【DP】
很有意思的题目. 题目背景 加特林轮盘赌是一个养生游戏. 题目描述 与俄罗斯轮盘赌等手枪的赌博不同的是,加特林轮盘赌的赌具是加特林. 加特林轮盘赌的规则很简单:在加特林的部分弹夹中填充子弹.游戏的参加 ...
- php引擎文件php.ini优化参数
无论是Apache环境还是nginx环境,php.ini都适合,php-fpm.conf适合nginx+fcgi的配置. 生产环境php.ini(php.ini-production) php.ini ...
- 80x25彩色字符模式
80x25彩色字符模式下显示缓冲区的结构: 在内存地址空间中,B8000H~BFFFFH共32KB的空间,为80x25彩色字符模式的显示缓冲区.往这个地址空间中写入数据,写入的内容会立即出现在显示器上 ...
- spring data jpa 动态查询(工具类封装)
利用JPA的Specification<T>接口和元模型就实现动态查询了.但是这样每一个需要动态查询的地方都需要写一个这样类似的findByConditions方法,小型项目还好,大型项目 ...
- java练习题:现给出二组字符串,比较他们看是否相等
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import jav ...
- 【ExtJS】一个简单的TreePanel
在ExtJS中,构造一个树形结构变得很简单. 需要用到的: Ext.tree.Panel TreePanel提供树形结构的UI表示的树状结构数据. 一个TreePanel必须绑定一个Ext.data. ...
- C++ 隐含的this 指针
c++primer 页数:376-379 备份, 很有嚼头 #include <iostream> #include <string> #include <fstre ...
- haproxy 503 service unavailable no server is avaible to handle this request
原因: haproxy 对server检测时是对默认页面进行检测,如果没有默认错误,则直接报503错误,不会转发到相应的server上去. 解决方法: 添加 option httpchk 检测页面位置 ...
- axios的兼容性
axios的兼容性处理 一.简介 看看官网的简介: “Promise based HTTP client for the browser and node.js” 译:基于 Promise 的 H ...
- AtCoder Grand Contest 006 F - Blackout
Description 在 \(n*n\) 的棋盘上给出 \(m\) 个黑点,若 \((x,y)\),\((y,z)\) 都是黑点,那么 \((z,x)\) 也会变成黑点,求最后黑点的数量 题面 So ...