hdoj 1159 Common Subsequence【LCS】【DP】
Common Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 28494 Accepted Submission(s): 12735
..., 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.
abcfbc abfcab
programming contest
abcd mnp
4
2
0
希望能够帮助大家。
#include<stdio.h>
#include<string.h>
#define max(a,b) (a>b? a:b)
char a[1000],s[1000];
int dp[1000][1000];
int main()
{
int i,j,k;
while(scanf("%s%s",a,s)!=EOF)
{
memset(dp,0,sizeof(dp));
int l=strlen(a);
int le=strlen(s);
for(i=1;i<=l;i++)
{
for(j=1;j<=le;j++)
if(a[i-1]==s[j-1])//推断左側和上側字符是否相等
dp[i][j]=dp[i-1][j-1]+1;//把左上側的dp值+1
else
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);//取左側或上側的最大dp值
}
printf("%d\n",dp[l][le]);
}
return 0;
}
hdoj 1159 Common Subsequence【LCS】【DP】的更多相关文章
- HDOJ 1159 Common Subsequence【DP】
HDOJ 1159 Common Subsequence[DP] Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 1159 Common Subsequence(裸LCS)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...
- hdu 1159 Common Subsequence(最长公共子序列 DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...
- HDOJ --- 1159 Common Subsequence
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- Hdoj 1159.Common Subsequence 题解
Problem Description A subsequence of a given sequence is the given sequence with some elements (poss ...
- hdu 1159 Common Subsequence(LCS)
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1159 Common Subsequence:LCS(最长公共子序列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 题意: 求最长公共子序列. 题解: (LCS模板题) 表示状态: dp[i][j] = max ...
- hdu 1159 Common Subsequence(最长公共子序列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...
- HDU 1159 Common Subsequence
HDU 1159 题目大意:给定两个字符串,求他们的最长公共子序列的长度 解题思路:设字符串 a = "a0,a1,a2,a3...am-1"(长度为m), b = "b ...
随机推荐
- JDK的安装及配置环境变量
开发java程序的必备工具:JDK,全名是Java Development Kit, 是Java语言的软件开发工具包. 第一步:下载安装包 从Oracle官网可以选择自己所需的版本下载,(附Oracl ...
- Linux 经常使用快捷键
桌面下: Alt+F5 取消最大化窗体 Alt+F9 最小化窗体 Alt+F10 最大化窗体 Alt+空格 打开窗体的控制菜单 (点击窗体左上角图标出现的菜单) ctl+r ...
- 2.安装 CLI和CLI的工作原理
转自:https://www.gruntjs.net/getting-started 还在使用 Grunt 0.3 版本吗?请查看 Grunt 0.3 注意事项 在继续学习前,你需要先将Grunt命令 ...
- springboot actuator shutdown正确的关闭操作
今天整合ehcache时发现一个很重要的问题,就是程序关闭(硬关闭)之后,持久化到磁盘的缓存数据没能正确写入加载,问题还是硬关闭的问题,所以就使用actuator 进行监听 <dependenc ...
- python制造模块
制造模块: 方法一: 1.mkdir /xxcd /xx 2.文件包含: 模块名.py setup.py setup.py内容如下:#!/usr/bin/env pythonfrom distutil ...
- orac
#!/bin/bash # Copyright (c) 2013, 2016, Liang Guojun. All rights reserved. # Program: # Check ...
- 24 款必备的 Linux 桌面应用(2016 版)
作者: Munif Tanjim 译者: LCTT GHLandy | 2016-12-21 08:41 评论: 41 收藏: 13 摘要:Linux 的必备软件有哪些?这将会是一个非常主观的回答 ...
- iOS开发——剪切板
剪切板的调用是很简单的,常用的就这两个,不管文字或是图片的粘贴复制,对剪切板的操作就是基于下面两个属性的: [UIPasteboard generalPasteboard].string [UIPas ...
- 20180929 北京大学 人工智能实践:Tensorflow笔记05
(完)
- STM32中断名词
1.NVIC的优先级概念 占先式优先级 (pre-emption priority): 高占先式优先级的中断事件会打断当前的主程序/中断程序运行— —抢断式优先响应,俗称中断嵌套. ...