hdu1159 Common Subsequence--DP
发布日期:2021-10-03 20:31:53 浏览次数:3 分类:技术文章

本文共 1647 字,大约阅读时间需要 5 分钟。

原题链接:

一:原题链接

Problem Description
A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = <x1, x2, ..., xm> another sequence Z = <z1, z2, ..., zk> is a subsequence of X if there exists a strictly increasing sequence <i1, i2, ..., ik> of indices of X such that for all j = 1,2,...,k, xij = zj. For example, Z = <a, b, f, c> is a subsequence of X = <a, b, c, f, b, c> with index sequence <1, 2, 4, 6>. Given two sequences X and Y the problem is to find the length of the maximum-length common subsequence of X and Y.
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.
 
Sample Input
abcfbc abfcabprogramming contest abcd mnp
 
Sample Output
420

二:分析理解

给出两个字符串,求两个字符串的最长公共字串。

可以看出:

F[i][j]=F[i-1][j-1]+1;(a[i]==b[j])
F[i][j]=max(F[i-1][j],F[i][j-1]);(a[i]!=b[j])

三:AC代码

#include
#include
#include
using namespace std;char a[1001] = "#";char b[1001] = "#";int dp[1005][1005] = { 0 };int main(){ while (~scanf("%s%s", a + 1, b + 1))//加上~,不然超时,醉了 { int a_len = strlen(a) - 1; int b_len = strlen(b) - 1; for (int i = 1; i <= a_len; i++) { for (int j = 1; j <= b_len; j++) { if (a[i] == b[j]) dp[i][j] = dp[i - 1][j - 1] + 1; else dp[i][j] = max(dp[i][j - 1], dp[i - 1][j]); } } printf("%d\n", dp[a_len][b_len]); } return 0;}

转载地址:https://blog.csdn.net/LaoJiu_/article/details/50944094 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:hdu2577 How to Type---DP
下一篇:hdu1176 免费馅饼--DP

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月16日 03时30分25秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

LiveNVR非国标流转GB28181配置连接REDIS通过redis订阅通道状态 2019-04-27
LiveGBS国标GB/T28181视频流媒体平台UDP、TCP被动、TCP主动的区别 2019-04-27
LiveGBS国标GB/T28181视频流媒体平台支持对接下级平台已有录像中心检索及模糊查询 2019-04-27
GB28181国标流媒体服务平台Linux与Windows系统中如何抓包分析UDP视频流丢包率网络质量视频质量分析信令交互 2019-04-27
海康大华摄像头GB/T28181接入国标视频平台如何选择主码流还是子码流 2019-04-27
LiveNVR视频拉流网关流媒体服务支持通过webrtc视频流播放超低延时播放 2019-04-27
传统大华海康宇视安防摄像头RTSP流如何转webrtc直播低延时无插件浏览器视频播放 2019-04-27
浏览器FLASH禁用后无法播放rtmp流怎么办webrtc视频流直播浏览器无插件播放也支持rtmp拉转成webrtc输出 2019-04-27
LiveGBS国标GB28181视频平台支持WebRTC低延时无插件直播解决flash禁用rtmp流无法播放问题 2019-04-27
LiveGBS国标获取接入海康大华宇视摄像机设备通道的视频流直播地址 HLS/HTTP-FLV/WS-FLV/WebRTC/RTMP/RTSP 2019-04-27
LiveNVR视频流拉转接入传统海康大华宇视安防摄像机如何获取通道视频直播流地址 RTSP/WebRTC/RTMP/HLS/HTTP-FLV/WS-FLV 2019-04-27
LiveNVR超低延时WebRTCP视频播放接口集成调用时候遇到401 Unauthorized 怎么办? 2019-04-27
LiveQing直播点播流媒体OBS推流直播如何获得接口校验token视频校验streamToken及配置token有效期 2019-04-27
LiveQing直播RTMP点播视频流媒体平台如何携带登录接口返回的sid和token接口调用鉴权streamToken视频流鉴权 2019-04-27
海康联网网关大华宇视下级平台如何配置上级域对接到LiveGBS国标GB/T28181视频流媒体平台 2019-04-27
如何将监控画面嵌入微信公众号进行直播 2019-04-27
国标流媒体服务中宇视4G设备采用GB/T28181协议成功接入 2019-04-27
LiveGBS接入LiveQing流媒体服务实现云端录像和大屏展示 2019-04-27
网页直播/点播播放器支持http-flv/rtmp/m3u8等播放终身免费 2019-04-27
国标GB28181流媒体无插件直播-播放鉴权进行安全播控 2019-04-27