每日一九度之 题目1042:Coincidence
时间限制:1 秒
内存限制:32 兆
特殊判题:否
提交:3007
解决:1638
- 题目描述:
-
Find a longest common subsequence of two strings.
- 输入:
-
First and second line of each input case contain two strings of lowercase character a…z. There are no spaces before, inside or after the strings. Lengths of strings do not exceed 100.
- 输出:
-
For each case, output k – the length of a longest common subsequence in one line.
- 样例输入:
-
abcd
cxbydz
- 样例输出:
-
2
经典的dp问题。LCS。相当于dp的入门级题目吧!
//Asimple
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <limits.h>
#define INF 0x7fffffff
using namespace std;
const int maxn = ;
typedef long long ll;
int n, num;
char s1[maxn], s2[maxn];
int dp[maxn][maxn]; int main(){
while( cin >> s1 >> s2 ){
int len1 = strlen(s1);
int len2 = strlen(s2);
for (int i=; i<=len1; ++i)
dp[i][] = ;
for (int j=; j<=len2; ++j)
dp[][j] = ;
for(int i=; i<=len1; i++){
for(int j=; j<=len2; j++){
if( s1[i-] == s2[j-] ){
dp[i][j] = dp[i-][j-] + ;
} else {
dp[i][j] = max(dp[i-][j],dp[i][j-]);
}
}
}
printf("%d\n",dp[len1][len2]);
}
return ;
}
每日一九度之 题目1042:Coincidence的更多相关文章
- 每日一九度之 题目1076:N的阶乘
时间限制:3 秒 内存限制:128 兆 特殊判题:否 提交:7601 解决:2749 题目描述: 输入一个正整数N,输出N的阶乘. 输入: 正整数N(0<=N<=1000) 输出: 输入可 ...
- 每日一九度之 题目1043:Day of Week
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:7336 解决:2563 题目描述: We now use the Gregorian style of dating in Russia. ...
- 每日一九度之 题目1041:Simple Sorting
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4883 解决:1860 题目描述: You are given an unsorted array of integer numbers. ...
- 每日一九度之 题目1040:Prime Number
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6732 解决:2738 题目描述: Output the k-th prime number. 输入: k≤10000 输出: The k- ...
- 每日一九度之 题目1038:Sum of Factorials
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2109 解决:901 题目描述: John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, ...
- 每日一九度之 题目1039:Zero-complexity Transposition
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3372 解决:1392 题目描述: You are given a sequence of integer numbers. Zero-co ...
- 每日一九度之 题目1033:继续xxx定律
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5502 解决:1351 题目描述: 当n为3时,我们在验证xxx定律的过程中会得到一个序列,3,5,8,4,2,1,将3称为关键数, ...
- 每日一九度之 题目1031:xxx定律
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6870 解决:4302 题目描述: 对于一个数n,如果是偶数,就把n砍掉一半:如果是奇数,把n变成 3*n+ 1后砍掉一半,直到该数 ...
- 每日一九度之 题目1030:毕业bg
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2046 解决:894 题目描述: 每年毕业的季节都会有大量毕业生发起狂欢,好朋友们相约吃散伙饭,网络上称为“bg”.参加不同团体的b ...
随机推荐
- ReactiveCocoa的使用方法
http://www.open-open.com/lib/view/open1440060663129.html best praticse https://github.com/ReactiveCo ...
- grunt搭建前端自动化实践
grunt是什么? grunt是一个前端构建工具, 每种应用开发, 都有一套构建工具, 例如linux c程序开发, 构建工具是make, java程序的构建工具为maven,web前端经过十多年的发 ...
- NET4.5之初识async与await
这是两个关键字,用于异步编程.我们传统的异步编程方式一般是Thread.ThreadPool.BeginXXX.EndXXX等等.把调用.回调分开来,代码的逻辑是有跳跃的,于是会导致思路不是很清晰的问 ...
- HTML语言的一些元素(四)
以下资料整理自网路 1.锚点是网页制作中超级链接的一种,又叫命名锚记.命名锚记像一个迅速定位器一样是一种页面内的超级链接,运用相当普遍. 英文名:anchor 使用命名锚记可以在文档中设置标记,这些标 ...
- spawn-fcgi
spawn-fcgi与PHP-FPM 前面介绍过,FastCGI接口方式在脚本解析服务器上启动一个或者多个守护进程对动态脚本进行解析,这些进程就是FastCGI进程管理器,或者称为FastCGI引擎. ...
- git的基本使用
1.在本地新建一个文件夹来存放代码 2.用命令行进入这个文件夹 3.git init --来创建一个代码仓库 3. 配置用户信息:用户名和 邮箱(联系作者本人沟通, 责任到人) git config ...
- 去掉字符串中的空格 JS JQ 正则三种不同写法
<script> function trim(str) { return str.replace(/(^\s*|\s*$)/g, "") } console.log(t ...
- Eclipse安装Ruby插件应该注意的几点
http://www.aptana.com/products/studio3/success_plugin.html Installing via Eclipse Please copy the fo ...
- AS-demo09
,mainifast: <uses-permission android:name="android.permission.SET_WALLPAPER"/> , < ...
- JAVA测试装饰者模式
package shb.java.demo; /** * 测试装饰者模式 * @package :shb.java.demoJava02 * @author shaobn * @Describe : ...