时间限制: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的更多相关文章

  1. 每日一九度之 题目1076:N的阶乘

    时间限制:3 秒 内存限制:128 兆 特殊判题:否 提交:7601 解决:2749 题目描述: 输入一个正整数N,输出N的阶乘. 输入: 正整数N(0<=N<=1000) 输出: 输入可 ...

  2. 每日一九度之 题目1043:Day of Week

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:7336 解决:2563 题目描述: We now use the Gregorian style of dating in Russia. ...

  3. 每日一九度之 题目1041:Simple Sorting

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4883 解决:1860 题目描述: You are given an unsorted array of integer numbers. ...

  4. 每日一九度之 题目1040:Prime Number

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6732 解决:2738 题目描述: Output the k-th prime number. 输入: k≤10000 输出: The k- ...

  5. 每日一九度之 题目1038:Sum of Factorials

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2109 解决:901 题目描述: John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, ...

  6. 每日一九度之 题目1039:Zero-complexity Transposition

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3372 解决:1392 题目描述: You are given a sequence of integer numbers. Zero-co ...

  7. 每日一九度之 题目1033:继续xxx定律

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5502 解决:1351 题目描述:     当n为3时,我们在验证xxx定律的过程中会得到一个序列,3,5,8,4,2,1,将3称为关键数, ...

  8. 每日一九度之 题目1031:xxx定律

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:6870 解决:4302 题目描述:     对于一个数n,如果是偶数,就把n砍掉一半:如果是奇数,把n变成 3*n+ 1后砍掉一半,直到该数 ...

  9. 每日一九度之 题目1030:毕业bg

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:2046 解决:894 题目描述:     每年毕业的季节都会有大量毕业生发起狂欢,好朋友们相约吃散伙饭,网络上称为“bg”.参加不同团体的b ...

随机推荐

  1. electron "Cannot find module 'dialog'", source: module.js (336)"

    打算用electron的dialog api 谁知道, 按官方api http://electron.atom.io/docs/v0.33.0/api/dialog/ https://github.c ...

  2. mini install centOS log

    no ifconfig yum install net-tools ------------------------------------------------------------------ ...

  3. jeasyui datagrid 使用记

    1. 一开始想用$('#dg').datagrid('getChanges')来保存整个table修改的行, 结果发现当前编辑的行不算,要失去焦点才有记录 2. 然后改用       $('#dg') ...

  4. 遇到could not find developer disk image 问题怎么解决

    一般是设备的版本低于或者高于当前的xcode

  5. G面经prepare: Sort String Based On Another

    Given a sorting order string, sort the input string based on the given sorting order string. Ex sort ...

  6. codeforces 520 Pangram

    http://codeforces.com/problemset/problem/520/A A. Pangram time limit per test 2 seconds memory limit ...

  7. 去掉字符串中的空格 JS JQ 正则三种不同写法

    <script> function trim(str) { return str.replace(/(^\s*|\s*$)/g, "") } console.log(t ...

  8. jquery ajax 个人总结

    jquery : 在获取对象的时候,不要用dem的与jquery的混合写法,有的时候 用js获取到的对象 没有JQUERY对应的方法  会报一些不知道的错误.(即如果要使用jquery 就使用jque ...

  9. C++之路起航——标准模板库(deque)

    deque(双端队列):http://baike.baidu.com/link?url=JTvA2cuLubptctHZwFxswvlZvxNdFOxmifsYCGLj5IZF-Tj4rbWLv8Jn ...

  10. struts自定义拦截器

    第01步:配置web.xml,启动struts框架 <?xml version="1.0" encoding="UTF-8"?> <web-a ...