hdu 1159 Common Subsequence (dp乞讨LCS)
Common Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 24489 Accepted Submission(s): 10823
..., 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>
#include<vector>
#include<iostream>
using namespace std;
int main(int argc, char *argv[])
{
string a,b;
while(cin>>a>>b)
{
vector<vector<int> > c;
int x=a.size();
int y=b.size();
int SIZE=x>y?x:y;
SIZE+=1;
c.resize(SIZE);
for(int i=0;i<SIZE;++i)
c[i].resize(SIZE,0);
for(int i=0;i<=x;++i)
c[i][0]=0;
for(int i=0;i<=y;++i)
c[0][i]=0;
for(int i=1;i<=x;++i)
for(int j=1;j<=y;++j)
{
if(a[i-1]==b[j-1])
{
c[i][j]=c[i-1][j-1]+1;
}
else
{
c[i][j]=c[i][j-1]>c[i-1][j]?c[i][j-1]:c[i-1][j];
}
}
cout<<c[x][y]<<endl; }
return 0;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
hdu 1159 Common Subsequence (dp乞讨LCS)的更多相关文章
- HDU 1159 Common Subsequence --- DP入门之最长公共子序列
题目链接 基础的最长公共子序列 #include <bits/stdc++.h> using namespace std; ; char c[maxn],d[maxn]; int dp[m ...
- HDU 1159 Common Subsequence
HDU 1159 题目大意:给定两个字符串,求他们的最长公共子序列的长度 解题思路:设字符串 a = "a0,a1,a2,a3...am-1"(长度为m), b = "b ...
- HDU 1159 Common Subsequence 最长公共子序列
HDU 1159 Common Subsequence 最长公共子序列 题意 给你两个字符串,求出这两个字符串的最长公共子序列,这里的子序列不一定是连续的,只要满足前后关系就可以. 解题思路 这个当然 ...
- 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 ...
- HDU 1159 Common Subsequence 公共子序列 DP 水题重温
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1159 Common Subsequence Time Limit: 2000/1000 MS (Jav ...
- 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 【LCS 基础入门】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1159 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- HDU 1159 Common Subsequence【dp+最长公共子序列】
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- IAR FOR ARM 各版本号,须要的大家能够收藏了
首先感谢大家的支持与关注,如今应该又一次编辑这篇文章了,这篇文章是非常久曾经不知在什么地方Copy过来的, 非常多问题不知怎么解决,如今我用的是KEIL for arm. 用过Keil和IAR,个人感 ...
- Python 的PyCurl模块使用
PycURl是一个C语言写的libcurl的python绑定库.libcurl 是一个自由的,并且容易使用的用在客户端的 URL 传输库.它的功能很强大,PycURL 是一个非常快速(参考多并发操作) ...
- js调用百度地图接口
原文:js调用百度地图接口 这是前几天公司做的新项目,上面需要用到地图的数据.第一次做这类型的东西没啥思路,咱们经理说,这东西简单,截个图存文件夹里调整好尺寸,数据库里存上图片的地址动态调用就行了.心 ...
- minihomepage.exe 百度视频迷你主页
百度视频最近动作可真.延续"DHot.exe 热点资讯"之后,又在桌面上出现了Tips窗体,例如以下图: 尽管是迷你的,可还是把其他桌面图标给挡了啊! 突然出来这么个窗体.我还以为 ...
- 发布Ubuntu/Linux系统cache,增加可用内存空间
桌面Ubuntu总内存4G,但free只有内存有100M 重视top命令检查看到真正的能力free内存.以下是真正的内存使用情况的看法有一个命令. watch -n 1 cat /proc/memin ...
- JAVA jdbc(数据库连接池)学习笔记(转)
学习内容: 1.JDBC的含义... JDBC想必学过JAVA的就不会陌生,JDBC到底是什么呢?其实就是由JAVA的一些类和接口构成的API,保存在java.sql和javax.sql..包中的一些 ...
- 【程序员联盟】官网上线啦!coderunity.com
内容简介 欢天喜地,[程序员联盟]官网上线咯(此处应该有鸡蛋丢过来...) [程序员联盟]官网 大家也许会问:“这几天小编都没出文章,跑哪里happy去啦?是不是偷懒去了?” 小编:“臣妾冤枉啊.” ...
- 我收集的sonar参考资料
sonarQube代码质量管理工具环境筹建笔记 http://www.myexception.cn/open-source/1307345.html 配置sonar.jenkins进行持续审查 htt ...
- 将EBS设为首页worklist删除误报
参考:How To Remove Error Notifications From The Worklist (Doc ID 357904.1) 1.1. Use one of the error n ...
- 轻量级的内部测试过程r \\ u0026研发团队
对于一个r \\ u0026研发团队的目的,标准化的工作流程资产不可或缺的一部分,特别是对于初创的r \\ u0026研发团队方面.很多r \\ u0026研发管理是不够完整.如何理解的研发团队中的各 ...