HDUOJ--1159Common Subsequence
Common Subsequence
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 19595 Accepted Submission(s): 8326
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.
int lcs(const char *a,const char *b)
{
int i,j;
int m=strlen(a),n=strlen(b);
mar[][]=;
for(i=;i<=m;i++)
mar[i][]=;
for(i=;i<=n;i++)
mar[][i]=;
for(i=;i<=m;i++)
{
for(j=;j<=n;j++)
{
if(a[i-]==b[j-])
mar[i][j]=mar[i-][j-]+;
else
mar[i][j]=mar[i-][j]>mar[i][j-]?mar[i-][j]:mar[i][j-];
}
}
return mar[m][n];
}
此题的代码:
#include<stdio.h>
#include<string.h>
#define maxn 1000
int mar[maxn][maxn];
char x[maxn],y[maxn]; int lcs(const char *a,const char *b)
{
int i,j;
int m=strlen(a),n=strlen(b);
mar[][]=;
for(i=;i<=m;i++)
mar[i][]=;
for(i=;i<=n;i++)
mar[][i]=;
for(i=;i<=m;i++)
{
for(j=;j<=n;j++)
{
if(a[i-]==b[j-])
mar[i][j]=mar[i-][j-]+;
else
mar[i][j]=mar[i-][j]>mar[i][j-]?mar[i-][j]:mar[i][j-];
}
}
return mar[m][n];
}
int main()
{
while(scanf("%s%s",&x,&y)!=EOF)
printf("%d\n",lcs(x,y));
return ;
}
HDUOJ--1159Common Subsequence的更多相关文章
- HDUOJ ---1423 Greatest Common Increasing Subsequence(LCS)
Greatest Common Increasing Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- [LeetCode] Arithmetic Slices II - Subsequence 算数切片之二 - 子序列
A sequence of numbers is called arithmetic if it consists of at least three elements and if the diff ...
- [LeetCode] Is Subsequence 是子序列
Given a string s and a string t, check if s is subsequence of t. You may assume that there is only l ...
- [LeetCode] Wiggle Subsequence 摆动子序列
A sequence of numbers is called a wiggle sequence if the differences between successive numbers stri ...
- [LeetCode] Increasing Triplet Subsequence 递增的三元子序列
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...
- [LeetCode] Longest Increasing Subsequence 最长递增子序列
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- 动态规划求最长公共子序列(Longest Common Subsequence, LCS)
1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...
- 【LeetCode】Increasing Triplet Subsequence(334)
1. Description Given an unsorted array return whether an increasing subsequence of length 3 exists o ...
- CF724D. Dense Subsequence[贪心 字典序!]
D. Dense Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
随机推荐
- Objective-C:NSString类的常见用法
几种常见的用法为:字符串的创建.字符串的搜索.字符串的比较.字符串的转换 用途一:字符串的创建 void ex1() { //1.常量字符串的对象 NSString *str1 = @"he ...
- super-pow
// https://discuss.leetcode.com/topic/50489/c-clean-and-short-solution class Solution { ; int powMod ...
- 第二章 mybatis使用注解实现in查询(mysql)
mybatis实现in查询,两种方法: xml形式(推荐) 注解方式(个人喜欢注解,但是in场景可能不太适合注解) 代码: @Select("<script>" + & ...
- 80端口占用异常解决方法java.net.BindException: Address already in use: JVM_Bind:80(或8080)
1:Tomcat(或其他Web容器)启动时控制台报错如下示: 2007-8-2 15:20:43 org.apache.coyote.http11.Http11Protocol init 严重: Er ...
- JQuery缓冲加载图片插件lazyload.js的使用方法
lazyload.js是一个基于JQuery的插件,可以用来缓冲加载图片.如果一个网页很长并且有很多图片的话,下载图片就需要很多时间,那么就会影响整个网页的加载速度,而这款延迟加载插件,会通过你的滚动 ...
- jquery圆角插件
为了实现div的圆角效果,你还在用古老的背景图片拼凑的方法吗?还是在用各种浏览器不互相兼容的CSS方式?如果你还在用这样的方式实现圆角,那我告诉你你真的out了,或许是我out了,竟然以前没发现有这样 ...
- JS操作JSON常用方法
一.JSON字符串的替换 工作经常遇到这样的字符串,如下: 需要经过替换后,才能从字符串转化成JSON对象.这里我们需要用JS实现replaceAll的功能, 将所有的 ' \\" ' 替换 ...
- CSS中英文字符两端对齐实现
两端对齐实现 一般加上下面2行就可实现 display: inline-block; text-align: justify; 但是对于中英文混杂的情况,中英文难一起实现对齐,原因在下面有分析,需要如 ...
- PL/SQL 下 Command window 与 SQL window 的区别
1.Command window实现了SQL*Plus的所有功能,允许运行sql*plus命令,sql命令,sql脚本. 2.SQL window用于执行sql语句,显示sql输出,执行统计信息.(测 ...
- Linux系统多网卡绑定实战
导读 对于服务器来说,网络设备的稳定也是比较重要的,特别是网卡.在生产型的系统中,网卡的可靠性就更为重要了. 多块网卡绑定到一个IP地址,当一块网卡发生物理性损坏的情况下,另一块网卡自动启用,并提供正 ...