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 ...
随机推荐
- gson学习以及进阶文章推荐
Json转换利器Gson之实例一-简单对象转化和带泛型的List转化 (http://blog.csdn.net/lk_blog/article/details/7685169)Json转换利器Gso ...
- Codeforces Round #364 (Div. 2) D. As Fast As Possible
D. As Fast As Possible time limit per test 1 second memory limit per test 256 megabytes input stand ...
- shell脚本中$
变量名只能包含数字.字母和下划线,因为某些包含其他字符的变量有特殊含义,这样的变量被称为特殊变量. 例如,$ 表示当前Shell进程的ID,即pid ./package/kernel/mac80211 ...
- HDU2629:Identity Card
Problem Description Do you own an ID card?You must have a identity card number in your family's Hous ...
- Django:之BBS项目
首先新建一个BBSProject项目,在建一个app,把app导入到项目中. 在项目BBSProject中的settings.py中, INSTALLED_APPS = [ 'django.contr ...
- MySQL慢日志查询全解析:从参数、配置到分析工具【转】
转自: MySQL慢日志查询全解析:从参数.配置到分析工具 - MySQL - DBAplus社群——围绕数据库.大数据.PaaS云,运维圈最专注围绕“数据”的学习交流和专业社群http://dbap ...
- Oracle where 0=1 or 1=1
本文转载自:http://www.cnblogs.com/junyuz/archive/2011/03/10/1979646.html sql where 1=1和 0=1 的作用 where 1 ...
- 【java】基础中的杂乱总结(二)
1 内部类进阶 package package8; //原则:先用内部类写 之后由于内部类匿名无法引用 用其继承的父类或实现的接口名 //再复写所有的抽象方法即可(是所有,否者还是抽象的,无法创建对象 ...
- OpenGL红宝书第一个例子:绘制两个三角形
1. 环境配置 在这里不在做环境配置的说明,因为网上可以找到很多类似的教程,如果有需要可以@我,我也希望能帮到大家,其它的不说了,先上我的代码 2. 第一个程序代码 创建LoadShader.h #p ...
- php redis 消息队列
redis是什么东西就不多说了,网上文章一搜一大堆. 首先来说一下我要实现的功能: 类似一个消息中转站吧,如果有人要发送消息,先将消息发到我这里来,然后我这边进行转发,为的就是有一个统一的管理和修改时 ...