hihocoder #1059 :String Matching Content Length

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

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的更多相关文章

  1. 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- ...

  2. hiho_1059_string matching content length

    题目大意 两个字符串strA和strB(长度最大为2100),他们中按照顺序有一些公共的子串,且公共子串的长度大于等于3,否则不认为是合法的,比如 abcdef 和 abcxcdef, 按照顺序有合法 ...

  3. 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 问题:调用第三 ...

  4. 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 ...

  5. Binary String Matching

    问题 B: Binary String Matching 时间限制: 3 Sec  内存限制: 128 MB提交: 4  解决: 2[提交][状态][讨论版] 题目描述 Given two strin ...

  6. NYOJ之Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述     Given two strings A and B, whose a ...

  7. ACM Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

  8. 南阳OJ----Binary String Matching

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

  9. Binary String Matching(kmp+str)

    Binary String Matching 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 Given two strings A and B, whose alp ...

随机推荐

  1. 关于个人网站选择虚拟主机还是VPS服务器的讨论

    还记得当初才开始学习建站的时候,选择的第一款虚拟主机是全HTML的主机,那时候的虚拟主机还分为HTML或者是ASP,PHP的都很少,在国内接触的学习较多还是以ASP为主,PHP是最近几年才开始流行.如 ...

  2. java代理的深入浅出(一)-Proxy

    java代理的深入浅出(一)-Proxy 1.什么是代理 代理模式是常用的java设计模式,他的特征是代理类与委托类有同样的接口,代理类主要负责为委托类预处理消息.过滤消息.把消息转发给委托类,以及事 ...

  3. 初探OpenGL(一)

    OPenGL ES 1.X 面向功能固定的硬件所涉及并提供加速支持,图形质量以及性能标准. OpenGL ES2.X则提供包括着色器技术在内的全编程3D图形算法.----硬件要求比较高. OpenGL ...

  4. Linux系统监控实用工具Glances

    Linux系统监控实用工具Glances Glances安装 Glances安装要求:python >= 2.6 和 psutil >= 0.4.1 1.第一步,安装了python-> ...

  5. a标签无跳转的死链接

    <a href="#" onclick="return false;">link1</a> <a href="javas ...

  6. C陷阱与缺陷 第一章

    1. 使用 e1=e2的赋值方式 作为 条件语句内部的判断,请使用显示的判断 不使用: if( x =y ) foo(); 而使用: ) foo(); 2. 注意编码规范,一定要在赋值号 “=”两边, ...

  7. 个人linux简单笔记,随时更新

    vim显示行数 :set nu 查找文件 find /home -name config.txt 重命名文件或者文件夹 mv a b centos中phpize的安装 yum install php- ...

  8. Linux 查硬件配置

    一:查看cpu more /proc/cpuinfo | grep "model name" grep "model name" /proc/cpuinfo 如 ...

  9. MyEclipse build path no actions available

    MyEclipse,是在eclipse 基础上加上自己的插件开发而成的功能强大的企业级集成开发环境,主要用于Java.Java EE以及移动应用的开发.MyEclipse的功能非常强大,支持也十分广泛 ...

  10. 转: oracle 存储过程 执行动态 实现sql

    http://jingyan.baidu.com/article/5d6edee2fbb9f999eadeecb9.html http://jingyan.baidu.com/article/3638 ...