每日一九度之 题目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 ...
随机推荐
- Servlet加载器的实验
今天,看了张孝祥老师的类加载器的一个高级实验分析的教程,有点受益匪浅. 新建servlet工程,在Servlet类中 package com.sinosoft.servelt; import java ...
- php:mysqli扩展
mysqli功能概述:http://php.net/manual/zh/mysqli.summary.php 代码(基本的用法):貌似可以防止sql注入 $root = "root" ...
- (Protype Pattern)原型模式
定义: 原型模式:用原型实例指定创建对象的种类,并且通过拷贝这些原型来创建新的对象 适用性: 当我们系统中有一些类,在使用的时候都有同样需要大量的创建,而这样的创建是复杂的而且是浪费CPU,内存资源的 ...
- Ways to access Oracle Database in PostgreSQL
Today, organizations stores information(data) in different database systems. Each database system ha ...
- 如何在RedHat6(7) or CentOS6(7)上制作无依赖的PostgreSQL数据库的RPM包
本文解决了源代码安装都需要先检查系统上是否安装了应用程序所依赖的软件包的烦恼,对源代码开发者也有一定的帮助.可以在该基础上进行适当的修改,以满足自己的要求. RedHat5 or CentOS5已经提 ...
- M面经prepare: Shuffle a deck
设计一个shuffle card 用了java. Random Class package Random; import java.util.*; public class Solution { st ...
- git的基本使用
1.在本地新建一个文件夹来存放代码 2.用命令行进入这个文件夹 3.git init --来创建一个代码仓库 3. 配置用户信息:用户名和 邮箱(联系作者本人沟通, 责任到人) git config ...
- 关于非阻塞connect的若干细节性问题
我们用man connection命令查看手册,如下: EINPROGRESS The socket is nonblocking and the connection cannot be com ...
- For 循环嵌套 0309
For ...
- EXCEL 删除重复项并保留最大最小值
自定义排序 框选需要主次排序的区域 开始—排序和筛选—自定义排序 添加筛选条件 若要获取最小值则次要关键字选择升序 排序后的数据 删除重复项 数据—删除重复项 选择要删除的列 删除A列的重复项后,B列 ...