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. 查看apk包及Activity名方法

    查看apk包名方法activity名: 方法一: aapt dump badging +客户端包所在路径+客户端包名称 如: aapt.exe dump badging K:\Apk\fanxing. ...

  2. hdu_5795_A Simple Nim(打表找规律的博弈)

    题目链接:hdu_5795_A Simple Nim 题意: 有N堆石子,你可以取每堆的1-m个,也可以将这堆石子分成3堆,问你先手输还是赢 题解: 打表找规律可得: sg[0]=0 当x=8k+7时 ...

  3. hdu_5762_Teacher Bo(鸽笼原理)

    题目链接:hdu_5762_Teacher Bo 题意: 给你n个点,问你能否找到两对点的曼哈顿距离相等 题解: 最开始看到这题,看数据以为要向nlogn的复杂度发展,结果经验误导了自己,我们仔细观察 ...

  4. hdu_1513_Palindrome(LCS+滚动数组)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1513 题意:给你一个字符串,问你最少插入多少个字符使其为回文字符. 题解:将字符串倒着保存,然后求一下 ...

  5. flash检测网络是否通畅

    air: 要在 Adobe ® Flash ® Professional(CS4 或更高版本)中使用 air.net 包: 选择“文件”>“发布设置”命令. 在 Flash 面板中,单击 Act ...

  6. Global事件执行顺序

    Global.asax 文件,有时候叫做 ASP.NET 应用程序文件,提供了一种在一个中心位置响应应用程序级或模块级事件的方法.你可以使用这个文件实现应用程序安全性以及其它一些任务.下面让我们详细看 ...

  7. Chrome不支持showModalDialog模态对话框和无法返回returnValue的问题

    父窗体部分js代码: var returnValue = window.showModalDialog("son.html ", window); //for chrome if ...

  8. 有了SSL证书,如何在IIS环境下部署https?【转载】

    昨天各位小伙伴都很开心的领取了自己的SSL证书,但是大部分小伙伴却不知道如何部署,也许是因为第一次接触SSL这种高端的东西吧,不过个人觉得就是懒懒懒...本来小编也挺懒的,但是答应了各位小伙伴的,那么 ...

  9. js1中call和apply的用法

    js1中call和apply的用法 е辊顷 饼蹭瑭 岚辗疥 碜坪命 笛攮鼠 鲳篝等 ざ遛膜 镀鞭冢蒯 晕 册薷濑 就不是抓了而是人拳啪啪两声两个人都被拳头打在了腿骨 许郾犍 国 ...

  10. [Java]知乎下巴第0集:让我们一起来做一个知乎爬虫吧哦耶【转】

    文章来源:http://jp.51studyit.com/article/details/16203.htm 作者:  汪海洋 身边的小伙伴们很多都喜欢刷知乎,当然我也不例外, 但是手机刷太消耗流量, ...