题目链接:http://codeforces.com/contest/682/problem/D

给你两个字符串,求两个字符串中顺序k个的相同子串 长度之和。(注意是子串)

dp[i][j][k][0] 表示a[i] == a[j]时,a字符串前i个和b字符串前j个,顺序k个相同的子串 长度之和

dp[i][j][k][1] 表示a[i] != a[j]时,顺序k个相同子串的长度之和

dp[i][j][k][0] = max(dp[i - 1][j - 1][k][0], dp[i - 1][j - 1][k - 1][1], dp[i - 1][j - 1][k - 1]) + 1;

dp[i][j][k][1] = max(dp[i - 1][j][k][1], dp[i][j - 1][k][1], dp[i][j][k][0], dp[i - 1][j][k][0], dp[i][j - 1][k][0]);

渣代码...

 //#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int N = 1e3 + ;
char str1[N], str2[N];
int dp[N][N][][]; int main()
{
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
scanf("%s %s", str1, str2);
for(int i = ; i <= n; ++i) {
for(int j = ; j <= m; ++j) {
for(int s = ; s <= k; ++s) {
if(str1[i - ] == str2[j - ]) {
dp[i][j][s][] = max(max(dp[i - ][j - ][s - ][], dp[i - ][j - ][s][]),
dp[i - ][j - ][s - ][]) + ;
}
dp[i][j][s][] = max(max(dp[i - ][j][s][], dp[i][j - ][s][]),
max(dp[i - ][j][s][], dp[i][j - ][s][]));
dp[i][j][s][] = max(dp[i][j][s][], dp[i][j][s][]);
}
}
}
printf("%d\n", dp[n][m][k][]);
return ;
}

Codeforces 682 D. Alyona and Strings (dp)的更多相关文章

  1. codeforces 682D D. Alyona and Strings(dp)

    题目链接: D. Alyona and Strings time limit per test 2 seconds memory limit per test 256 megabytes input ...

  2. Codeforces Round #358 (Div. 2) D. Alyona and Strings dp

    D. Alyona and Strings 题目连接: http://www.codeforces.com/contest/682/problem/D Description After return ...

  3. CF#358 D. Alyona and Strings DP

    D. Alyona and Strings 题意 给出两个字符串s,t,让找出最长的k个在s,t不相交的公共子串. 思路 看了好几个题解才搞懂. 代码中有注释 代码 #include<bits/ ...

  4. 【31.58%】【codeforces 682D】Alyona and Strings

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. D. Alyona and Strings 解析(思維、DP)

    Codeforce 682 D. Alyona and Strings 解析(思維.DP) 今天我們來看看CF682D 題目連結 題目 略,請直接看原題. 前言 a @copyright petjel ...

  6. Codeforces Round #358 (Div. 2) D. Alyona and Strings 字符串dp

    题目链接: 题目 D. Alyona and Strings time limit per test2 seconds memory limit per test256 megabytes input ...

  7. CodeForces 682D Alyona and Strings (四维DP)

    Alyona and Strings 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/D Description After re ...

  8. [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)

    [Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...

  9. [CodeForces - 1225E]Rock Is Push 【dp】【前缀和】

    [CodeForces - 1225E]Rock Is Push [dp][前缀和] 标签:题解 codeforces题解 dp 前缀和 题目描述 Time limit 2000 ms Memory ...

随机推荐

  1. HDU 1711 Number Sequence (数字KMP,变形)

    题意: 在一个序列中找到一个连续的子序列,返回其开始位置. 思路: 每个数字当成1个字符,长的序列是原串,短的序列是模式串,求next数组后进行匹配. #include <iostream> ...

  2. 【英语】Bingo口语笔记(64) - Beat系列

  3. mouseevent tips

    关于roll_over 和 mouse_over的区别,这篇文章说明的很清楚,http://zengrong.net/post/1105.htm 全文如下: 在MouseEvent中,ROLL_OVE ...

  4. 下载个jquery-easyui-1.3.0使用,把他导入到myeclipse10里,jquery-1.7.2.min.js报错。 错误如下, Syntax error on token "Invalid Regular Expression Options", no accurate correc

    1.选中报错的jquery文件“jquery-1.2.6.min.js”.2.右键选择 MyEclipse-->Exclude From Validation .3.再右键选择 MyEclips ...

  5. hdu 5423 Rikka with Tree(dfs)bestcoder #53 div2 1002

    题意: 输入一棵树,判断这棵树在以节点1为根节点时,是否是一棵特殊的树. 相关定义: 1.  定义f[A, i]为树A上节点i到节点1的距离,父节点与子节点之间的距离为1. 2.  对于树A与树B,如 ...

  6. Android 最火框架XUtils之注解机制详解

    http://blog.csdn.net/rain_butterfly/article/details/37931031

  7. 【LeetCode 234】Palindrome Linked List

    Given a singly linked list, determine if it is a palindrome. 思路: 用快慢指针找到链表中点,反转后半部分链表,然后与前半部分进行匹配,随后 ...

  8. loadrunner之C语言编程

    一.常量定义 #define COUNT 100            //定义全局常量#define SALARY 4000 Action(){    int total;    total = C ...

  9. 基于opencv的手写数字识别(MFC,HOG,SVM)

    参考了秋风细雨的文章:http://blog.csdn.net/candyforever/article/details/8564746 花了点时间编写出了程序,先看看效果吧. 识别效果大概都能正确. ...

  10. java PO、BO

    PO(persistent object) 持久对象 在o/r映射的时候出现的概念,如果没有o/r映射,那么这个概念也就不存在了.通常对应数据模型(数据库),本身还有部分业务逻辑的处理.可以看成是与数 ...