预处理下连续相等的字符个数其实主要是看是否满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的更多相关文章

  1. String Matching Content Length

    hihocoder #1059 :String Matching Content Length 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 We define the ...

  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. POJ 2431Expedition

    Description A group of cows grabbed a truck and ventured on an expedition deep into the jungle. Bein ...

  2. Fast Fourier Transform

    写在前面的.. 感觉自己是应该学点新东西了.. 所以就挖个大坑,去学FFT了.. FFT是个啥? 挖个大坑,以后再补.. 推荐去看黑书<算法导论>,讲的很详细 例题选讲 1.UOJ #34 ...

  3. js简单放羊式单元测试-上

    这是看了很多js单元测试资料后第一次自己做单元测试,因为资料都在介绍工具怎么使用,js单元测试的工具是在是太多了,各种风格,各种支持的,新的旧的,so 还是自己动手来体验一次 简单 是我给自己的需求很 ...

  4. odoo 中X2many类型的视图继承

    我们知道视图的继承可以使用inherit_id,但是对于诸如one2many类型的字段,如何利用xpath继承修改其视图呢? 问题:如果直接写one2many类型的字段,会报不存在该字段的错误: 原视 ...

  5. VerifyCodeUtil.java

    package com.vcredit.framework.utils; import java.awt.Color;import java.awt.Font;import java.awt.Grap ...

  6. 【emWin】例程五:显示数值

    实验指导书及代码包下载: 链接:http://pan.baidu.com/s/1pLexsAf密码:p0jf 实验现象:

  7. Java中的递归运算

    Java中的递归运算是一种在自己的方法内部调用自己的方法 递归的设计思想是:把一个复杂的问题,分解为若干个等同的子问题,重复执行,直到之问题能够简单到直接求解,这样复杂的问题就得以解决. 递归运算有两 ...

  8. python学习道路(day10note)(线程,进程)

    1.计算机的发展史 看alex的博客吧,了解一下可以了 2.线程与GIL简介 #线程 #一道单一的指令的控制流,寄生在进程中 #单一进程里的多个线程是共享数据的 #多个线程涉及修改共享数据的时候需要枷 ...

  9. Quartz2之入门示例【转】

    原文地址:http://liuzidong.iteye.com/blog/1118992 环境:XP+Myeclipse6.5+JDK1.6 quartz官网:http://www.quartz-sc ...

  10. pyspider 安装时 Could not run curl-config

    sudo aptitude install libcurl4-openssl-dev