HDU-1159-Common Subsequence
链接:https://vjudge.net/problem/HDU-1159#author=0
题意:
最长公共子序列,LCS
思路:
LCS
代码:
#include <iostream>
#include <memory.h>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <queue>
#include <string>
#include <stack>using namespace std;typedef long long LL;const int MAXN = 1000 + 10;int dp[MAXN][MAXN];int main()
{string a, b;while (cin >> a >> b){memset(dp, 0, sizeof(dp));int lena = (int)a.length();int lenb = (int)b.length();for (int i = 1;i <= lena;i++){for (int j = 1;j <= lenb;j++){if (a[i - 1] == b[j - 1])dp[i][j] = dp[i - 1][j - 1] + 1;elsedp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);}}cout << dp[lena][lenb] << endl;}return 0;
}
转载于:https://www.cnblogs.com/YDDDD/p/10630128.html
HDU-1159-Common Subsequence相关推荐
- HDU 1159.Common Subsequence【动态规划DP】
Problem Description A subsequence of a given sequence is the given sequence with some elements (poss ...
- HDU 1159 Common Subsequence 动态规划
2017-08-06 15:41:04 writer:pprp 刚开始学dp,集训的讲的很难,但是还是得自己看,从简单到难,慢慢来(如果哪里有错误欢迎各位大佬指正) 题意如下: 给两个字符串,找到其中 ...
- HDU 1159 Common Subsequence
题解:裸的LCS /*LCS*/ #include <iostream> #include <string> using namespace std; int f[1000][ ...
- hdu 1159 Common Subsequence (dp)
点击打开链接 题目意思: 简单DP应用.. 给你两个字符串看看有依次有多少字符相同, Dp[i][j]表示str_1的前i个字符与str_2的前J个字符有dp[i][j]个相同的. dp[i][j]= ...
- HD 1159 Common Subsequence (最长公共子序列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Problem Description A subsequence of a given seq ...
- 动态规划—最长公共子序列问题 HDU-1159 Common Subsequence
动态规划-最长公共子序列问题 Common Subsequence [ HDU - 1159 ] A subsequence of a given sequence is the given sequ ...
- C++longest common subsequence最长公共子序列的实现(附完整源码)
C++longest common subsequence最长公共子序列 longest common subsequence最长公共子序列的完整源码(定义,实现,main函数测试) longest ...
- Common Subsequence
原题及翻译 A subsequence of a given sequence is the given sequence with some elements (possible none) lef ...
- 【算法导论学习-29】动态规划经典问题02:最长公共子序列问题(Longest common subsequence,LCS)...
2019独角兽企业重金招聘Python工程师标准>>> 问题描述:序列X={x1,x2,-,xn},Y={y1,y2,-,yn},当Z={z1,z2-,zn}是X的严格递增下标顺序( ...
- UVA10405 Longest Common Subsequence【LCS+DP】
Given two sequences of characters, print the length of the longest common subsequence of both sequen ...
最新文章
- 干货 | 详解对象检测模型中的Anchors
- Redis 高可用篇:你管这叫主从架构数据同步原理?
- RxSwift之深入解析map操作符的底层实现
- mysql稠化报表_Oracle使用PARTITION BY 实现数据稠化报表
- JDK环境变量设置(linux)
- 机器学习与数据挖掘简介
- python怎么画图片 wafer map_Python wafer_map包_程序模块 - PyPI - Python中文网
- egg框架访问 Mysql 数据库 egg-mysql 增删改查
- 华为云PB级数据库GaussDB(for Redis)揭秘第五期:高斯 Redis 在IM场景中的应用
- ResNet卷积神经网络
- Centos6.x升级内核方法支持Docker
- html5介绍 之亮点特性
- xampp错误: mysql 非正常关闭._mysql数据库DBA实用技巧--为你的数据库开启Innodb监控...
- 使用js一行代码解决上网培训弹窗问题
- C# 以MDF文件连接数据库
- 有限温度量子多体系统与热态张量网络
- 《计算机网络教程》(微课版 第五版)第一章 概述 课后习题及答案
- #1.4股市预测数学的产生原因
- 色相/饱和度趣味调节
- 详解 box-shadow