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 ...
随机推荐
- UVa 12325 Zombie's Treasure Chest【暴力】
题意:和上次的cf的ZeptoLab的C一样,是紫书的例题7-11 不过在uva上交的时候,用%I64d交的话是wa,直接cout就好了 #include<iostream> #inclu ...
- Asp.Net验证码1
验证码html调用 验证码:<input name="> <img src="CodeHandler.ashx" id="imgCode&qu ...
- BZOJ 4408 神秘数
题解同各神犇的方法... #include<iostream> #include<cstdio> #include<cstring> #include<alg ...
- linux中备份mysql数据库的一个shell脚本
#!/bin/bash #FileName:select_into_bak.sh #Desc:Use select into outfile to backup db or tables #Creat ...
- 【C#学习笔记】改变字体
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- HDU 5003 Osu!
解题思路:水题,不多说. #include<cstdio> #include<cstring> #include<algorithm> #include<cm ...
- PPTP模式跟L2TP模式有什么不同
使用VPN的时候经常会看到商家说支持PPTP模式和L2TP模式,但是许多朋友都不知道有什么区别,该用哪一个,下面给你们讲讲: 1).PPTP协议是点对点隧道协议:其将控制包与数据包分开,控制包采用TC ...
- 微信 ua
Mozilla/5.0 (Linux; U; Android 2.3.6; zh-cn; GT-S5660 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, l ...
- SQL server2012连接不上
数据库连接不上 其中一种可能的解决办法: 开始-所有程序-Microsoft SQL server 2012-配置工具-SQL Server 配置管理器-SQL server 服务-SQL serve ...
- PHPMailer邮件类使用错误分析
PHPMailer配置清单如下: require_once ‘class.phpmailer.php‘; $receiver = ”; $mail = new PHPMailer ( ); $mai ...