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,j-2]+1这样才能保证连续让长度超过3的继续增加1
但是这里不通过直接[i-4,j-4]+3[i-1,j-1]判断因为不满足3的不算进来,比如[0,0]+3[3,3]可以但是[1,1]+3!=[4,4]因为[1,1]也是0,就不能推出[5,5]了,当然也可以用[3,3]+1==[4,4]或判断,不过数组下标-4就又把范围扩大了
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication12
{
class Program
{
public static int[,] dp;
public static int[,] pd;
static void Main(string[] args)
{
string nstr;
string mstr;
nstr = Console.ReadLine();
mstr = Console.ReadLine();
int n = nstr.Length;
int m = mstr.Length;
dp = new int[n, m];
pd = new int[n, m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (i < 1 || j < 1)
pd[i, j] = (nstr[i] == mstr[j] ? 1 : 0);
else
pd[i, j] = (nstr[i] == mstr[j] ? pd[i - 1, j - 1] + 1 : 0);
for (int i = 2; i < n; i++)
{
for(int j = 2; j < m; j++)
{
if (pd[i, j] >= 3)
{
if (i < 3 || j < 3)
dp[i, j] = 3;
else
dp[i, j] = Math.Max(dp[i, j], dp[i - 3, j - 3] + 3);
}
if(dp[i-1,j-1]!=dp[i-2,j-1]&&dp[i-1,j-1]!=dp[i-1,j-2])
dp[i, j] = Math.Max(dp[i, j], dp[i - 1, j - 1]+(pd[i,j]>=3?1:0));
dp[i, j] = Math.Max(dp[i, j], dp[i - 1, j]);
dp[i, j] = Math.Max(dp[i, j], dp[i, j - 1]);
}
}
Console.WriteLine(dp[n-1,m-1]);
}
}
}
Hihocoder 1059 String Matching Content Length的更多相关文章
- String Matching Content Length
hihocoder #1059 :String Matching Content Length 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 We define the ...
- 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 ...
随机推荐
- C#基础:委托
委托是C#中最为常见的内容.与类.枚举.结构.接口一样,委托也是一种类型.类是对象的抽象,而委托则可以看成是函数的抽象.一个委托代表了具有相同参数列表和返回值的所有函数.比如: delegate in ...
- 北京电子科技学院(BESTI)实验报告1
北京电子科技学院(BESTI)实验报告1 课程: 信息安全系统设计基础 班级:1452.1453 姓名:(按贡献大小排名)郑凯杰 .周恩德 学号:(按贡献大小排名)20145314 .20145217 ...
- 集中式vs分布式区别
记录一下我了解到的版本控制系统,集中式与分布式,它们之间的区别做下个人总结. 什么是集中式? 集中式开发:是将项目集中存放在中央服务器中,在工作的时候,大家只在自己电脑上操作,从同一个地方下载最新版本 ...
- Linux CentOS下安装Oracle
1 .在安装oracle之前首先安装以下组件包,直接输入下列语句安装. yum install binutils* -y yum install compat-lib* -y yum install ...
- [LintCode] Delete Node in the Middle of Singly Linked List 在单链表的中间删除节点
Implement an algorithm to delete a node in the middle of a singly linked list, given only access to ...
- MySQL 高可用架构之MMM
简介 MMM(Master-Master replication manager for MySQL)是一套支持双主故障切换和双主日常管理的脚本程序.MMM使用Perl语言开发,主要用来监控和管理My ...
- PDMS二次开发之PML开发一些常见查询语句
1.查找session 以及session number var !DBname DBname !db = object db(!DBname) !session = !db.lastsession( ...
- iOS,一行代码进行RSA、DES 、AES、MD5加密、解密
本文为投稿文章,作者:Flying_Einstein(简书) 加密的Demo,欢迎下载 JAVA端的加密解密,读者可以看我同事的这篇文章:http://www.jianshu.com/p/98569e ...
- java 使用map返回多个对象组装
Object json=JSONObject.fromObject("{}"); List<Object> list = new ArrayList<Object ...
- Python学习笔记 for windows 三
多重继承 继承是面向对象编程的一个重要的方式,因为通过继承,子类就可以扩展父类的功能. 哺乳类:能跑的哺乳类,能飞的哺乳类: 鸟类:能跑的鸟类,能飞的鸟类. class Animal(object): ...