Codeforces 682 D. Alyona and Strings (dp)
题目链接: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)的更多相关文章
- codeforces 682D D. Alyona and Strings(dp)
题目链接: D. Alyona and Strings time limit per test 2 seconds memory limit per test 256 megabytes input ...
- 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 ...
- CF#358 D. Alyona and Strings DP
D. Alyona and Strings 题意 给出两个字符串s,t,让找出最长的k个在s,t不相交的公共子串. 思路 看了好几个题解才搞懂. 代码中有注释 代码 #include<bits/ ...
- 【31.58%】【codeforces 682D】Alyona and Strings
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- D. Alyona and Strings 解析(思維、DP)
Codeforce 682 D. Alyona and Strings 解析(思維.DP) 今天我們來看看CF682D 題目連結 題目 略,請直接看原題. 前言 a @copyright petjel ...
- 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 ...
- CodeForces 682D Alyona and Strings (四维DP)
Alyona and Strings 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/D Description After re ...
- [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)
[Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...
- [CodeForces - 1225E]Rock Is Push 【dp】【前缀和】
[CodeForces - 1225E]Rock Is Push [dp][前缀和] 标签:题解 codeforces题解 dp 前缀和 题目描述 Time limit 2000 ms Memory ...
随机推荐
- poj 1195 mobile phone
题目连接: 题意:要求设计这样一个数据结构,支持下列操作 1.add(x,y,a).对二维数组的第x行,第y列加上a. 2.sum(l,b,r,t).求所有满足l<=x<=r,b<= ...
- C实现类封装、继承、多态
1. 概述 C语言是一种面向过程的程序设计语言,而C++是在C语言基础上衍生来了的面向对象的语言,实际上,很多C++实现的底层是用C语言实现的,如在Visual C++中的Interface其实就是 ...
- SAS使用SPD引擎并报Encoding错误
ERROR: Unable to open data file because its file encoding differs from the SAS session encoding and ...
- [转载] ubuntu开机直接进入命令行模式
最近安装了ubuntu12.04来使用,每次都进入unity界面再进入命令行很不方便. 不需要界面的话,可以通过设置来开机进入命令行模式. 今天提供两中比较好的方法.经本人测试两中方法都可使用. [1 ...
- Dataguard后台进程解析
Log Transport Service 主节点上,日志传输服务主要使用如下几个进程: 1.LGWR LGWR搜集事务日志,并且更新联机日志.在同步模式下,LGWR直接将redo信息直接 ...
- 《Unix网络编程》卷2 读书笔记 第3章- System V IPC
1. 概述 三种类型的System V IPC:System V 消息队列.System V 信号量.System V 共享内存区 System V IPC在访问它们的函数和内核为它们维护的信息上共享 ...
- android studio开发工具的android library打包文件(.aar)本地引用
by 蔡建良 2014-5-13 关键点: 利用Gradle发布本地maven库支持android library 打包文件(*.aar) 的本地引用 开发环境: windows7 64位操作系统 a ...
- myeclipse 8.5最新注册码(过期时间到2016年)
myeclipse 8.5最新注册码(过期时间到2016年) 这几天myeclipse弹出注册码过期,去网上一搜,要么已过期,要么就剩一两个月.倒腾了半天,自己申请了几个注册码,给大家分享一下 Sub ...
- Linux服务部署
1. 构建NTP时间服务器 NTP服务器是用于局域网服务器时间同步使用的,可以保证局域网所有的服务器与时间服务器的时间保持一致,某些应用对时间实时性要求高的必须统一时间.互联网的时间服务器也有很多,例 ...
- win8 VS控件信息
<TextBlock x:Name="button_1" HorizontalAlignment="Center" TextWrapping=" ...