String Matching Content Length
hihocoder #1059 :String Matching Content Length
描述
We define the matching contents in the strings of strA and strB as common substrings of the two strings. There are two additional restrictions on the common substrings.
The first restriction here is that every common substring's length should not be less than 3. For example:
strA: abcdefghijklmn
strB: ababceghjklmn
The
matching contents in strA and strB are substrings ("abc", "jklmn").
Note that though "e" and "gh" are common substrings of strA and strB,
they are not matching content because their lengths are less than 3.
The second restriction is that the start indexes of all common substrings should be monotone increasing. For example:
strA: aaabbbbccc
strB: aaacccbbbb
The
matching contents in strA and strB are substrings ("aaa", "bbbb"). Note
that though "ccc" is common substring of strA and strB and has length
not less than 3, the start indexes of ("aaa", "bbbb", "ccc") in strB are
(0, 6, 3), which is not monotone increasing.
输入
Two lines. The first line is strA and the second line is strB. Both strA and strB are of length less than 2100.
输出
The maximum length of matching contents (the sum of the lengths of the common substrings).
- 样例输入
-
abcdefghijklmn
ababceghjklmn - 样例输出
-
8
分析:与LCS不同的是加了每个子串长度不小于3,所以状态转移方程有
dp[i+1][j+1]=max({dp[i+1][j+1],dp[i][j]+ok[i-1][j-1],dp[i-2][j-2]+3}),当有连续3字符形成,且ok数组判断a,b字符串前一个字符是否有连续3字符形成。
代码:#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define vi vector<int>
#define pii pair<int,int>
#define mod 1000000007
#define inf 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
const int maxn=2e3+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,ma,dp[maxn][maxn],len1,len2,ok[maxn][maxn];
char a[maxn],b[maxn];
int main()
{
int i,j,k,t;
scanf("%s%s",a,b);
len1=strlen(a),len2=strlen(b);
rep(i,,len1-)rep(j,,len2-)
{
dp[i+][j+]=max(dp[i][j+],dp[i+][j]);
if(a[i]==b[j]&&a[i-]==b[j-]&&a[i-]==b[j-])
{
dp[i+][j+]=max({dp[i+][j+],dp[i][j]+ok[i-][j-],dp[i-][j-]+});
ok[i][j]=;
}
ma=max(ma,dp[i+][j+]);
}
printf("%d\n",ma);
//system ("pause");
return ;
}
String Matching Content Length的更多相关文章
- Hihocoder 1059 String Matching Content Length
预处理下连续相等的字符个数其实主要是看是否满3个 后面递推的时候特判下+1上次递推[i-1,j-1]不是来自[i-2,j-1]也不是来自[i-1,j-2]其实就是只来自[i-4,j-4]+3,和[i- ...
- hiho_1059_string matching content length
题目大意 两个字符串strA和strB(长度最大为2100),他们中按照顺序有一些公共的子串,且公共子串的长度大于等于3,否则不认为是合法的,比如 abcdef 和 abcxcdef, 按照顺序有合法 ...
- WCF常见异常-The maximum string content length quota (8192) has been exceeded while reading XML data
异常信息:The maximum string content length quota (8192) has been exceeded while reading XML data 问题:调用第三 ...
- The maximum string content length quota (8192) has been exceeded while reading XML data
原文:The maximum string content length quota (8192) has been exceeded while reading XML data 问题场景:在我们W ...
- Binary String Matching
问题 B: Binary String Matching 时间限制: 3 Sec 内存限制: 128 MB提交: 4 解决: 2[提交][状态][讨论版] 题目描述 Given two strin ...
- NYOJ之Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose a ...
- ACM Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- 南阳OJ----Binary String Matching
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
- Binary String Matching(kmp+str)
Binary String Matching 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 Given two strings A and B, whose alp ...
随机推荐
- HDU 5352 MZL's City
最小费用最大流,因为要控制字典序,网络流控制不好了...一直WA,所以用了费用流,时间早的费用大,时间晚的费用少. 构图: 建立一个超级源点和超级汇点.超级源点连向1操作,容量为K,费用为COST,然 ...
- 笔记整理--Linux多线程
Unix高级环境编程系列笔记 (2013/11/17 14:26:38) Unix高级环境编程系列笔记 出处信息 通过这篇文字,您将能够解答如下问题: 如何来标识一个线程? 如何创建一个新线程? 如何 ...
- c语言-error C2440: “static_cast”: 无法从“UINT (__thiscall CHyperLink::* )(CPoint)”转换为“LRESULT (__thiscall CWnd::* )(CPoint)”
出现这个错误的原因可是“人力不可抗拒”之原因造成的,因为旧版本的 ON_WM_NCHITTEST 宏使用了 UINT (__thiscall CWzButton::* )(CPoint); 类型的类成 ...
- python自动化测试
python自动化测试 欢迎光临 python自动化测试 小站! 小站基于IT行业,重点关注python,软件自动化测试,测试等. 联系方式 飞信 372818219 相关的群:python开发自动化 ...
- 缺少对象 WScript 问题解决方法
方法一: 先把脚本保存起来(保证你的脚本能正确运行),例如命名为test.vbs 然后在QTP写以下脚本就可以正确运行了! Dim oShell Set oShell =CreateObject (& ...
- const放在函数前和函数后
class c { public: returnType functionName (parameter list) const; //这个函数不会修改类成员 const returnType fun ...
- Centos中压缩(zip)和解压(unzip)命令
摘自:http://liuzhichao.com/p/681.html 1.我下载了一个yasuo.zip文件,想解压缩: # unzip yasuo.zip 2.我当前目录下有abc1.zip,ab ...
- jquery多级下拉菜单
var menu = new Click('#menu',{target:'p',parent:'li',contr:'ul',way:0}); /* 参数说明: target : 点击事件发生在该元 ...
- 在centos中配置maven
为了服务于jenkins,准备安装maven 首先在官网下载最新版本的maven,我此时的版本为apache-maven-3.3.9-bin.tar.gz 把该文件移到到/usr/local下 进行解 ...
- cmd命令行查看当前系统版本和版本是32位还是64位