$dp$。

$dp[i][j]$表示$s[i]$到$s[j]$和$t[lent-1+i-j]$到$t[lent-1]$有$dp[i][j]$位相同,然后枚举一遍$dp[i][j]$就可以算出答案了。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>
using namespace std; const int maxn=;
char s[maxn],t[maxn];
int lens,lent;
int dp[maxn][maxn]; int main()
{
memset(s,,sizeof s);
memset(t,,sizeof t);
scanf("%s%s",s,t);
lens=strlen(s), lent=strlen(t); for(int i=lens;i<lens+lent;i++) s[i]='.';
lens=strlen(s); int ans=; for(int Len=;Len<=lent;Len++)
{
for(int i=;i<lens;i++)
{
int j=i+Len-;
if(j>=lens) continue;
if(j==i)
{
if(s[i]==t[lent-]) dp[i][j]=;
else dp[i][j]=;
ans=min(ans,j-i+-dp[i][j]+lent-(j-i+));
}
else
{
dp[i][j]=dp[i+][j];
if(s[i]==t[lent-+i-j]) dp[i][j]++;
ans=min(ans,j-i+-dp[i][j]+lent-(j-i+));
}
}
} printf("%d\n",ans); return ;
}

CodeForces 157C Message的更多相关文章

  1. CodeForces 156A Message(暴力)

    A. Message time limit per test 2 seconds memory limit per test 256 megabytes input standard input ou ...

  2. OUC_Summer Training_ DIV2_#5

    这是做的最好的一次了一共做了4道题  嘻嘻~ A - Game Outcome Time Limit:2000MS     Memory Limit:262144KB     64bit IO For ...

  3. Eclipse 4.2 failed to start after TEE is installed

    ---------------  VM Arguments---------------  jvm_args: -Dosgi.requiredJavaVersion=1.6 -Dhelp.lucene ...

  4. Codeforces Round #396 (Div. 2) C. Mahmoud and a Message dp

    C. Mahmoud and a Message 题目连接: http://codeforces.com/contest/766/problem/C Description Mahmoud wrote ...

  5. Codeforces Round #396 (Div. 2) C. Mahmoud and a Message

    地址:http://codeforces.com/contest/766/problem/C 题目: C. Mahmoud and a Message time limit per test 2 se ...

  6. 【codeforces 766C】Mahmoud and a Message

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. Codeforces 766C:Mahmoud and a Message(DP)

    题目链接:http://codeforces.com/problemset/problem/766/C 题意 有一个长度为n的字符串,第二行有26个数字,位置1~26对应为a~z的字母,数值表示该字母 ...

  8. Codeforces 766C - Mahmoud and a Message

    C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  9. Codeforces 766C Mahmoud and a Message 2017-02-21 13:57 62人阅读 评论(0) 收藏

    C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

随机推荐

  1. Android Studio设置自己主动编project

    在Eclipse自己主动编译兄弟习惯,刚搬到Android Studio.当然,错过这个功能,自己主动编译每次执行意味着更短的时间. Android Studio里面事实上也是有自己主动编译功能的,只 ...

  2. 安装Windows2003操作系统 - 初学者系列 - 学习者系列文章

    Windows 2003是一款经典的服务器操作系统.以前笔者工作的时候就是用的这款操作系统来进行编程的.下面就对该操作系统的安装进行介绍(部分步骤参见XP的安装http://www.cnblogs.c ...

  3. 清空SQL Server数据库中所有表数据的方法

    原文:清空SQL Server数据库中所有表数据的方法 其实删除数据库中数据的方法并不复杂,为什么我还要多此一举呢,一是我这里介绍的是删除数据库的所有数据,因为数据之间可能形成相互约束关系,删除操作可 ...

  4. leetcode[88] Gray Code

    题目:格雷码. 格雷码是从0开始且之后两个相邻码之间只有一个符号不相同,例如000,100,101,111三个相邻之间只有一个二进制不同. 现在给定一个数字n,然后给出格雷码所对应的数字.例如: Fo ...

  5. ACE编译运行错误解决

    使用VS2010编译运行ACE版本号为6.0.1 按照网上步骤添加config.h,在ACE_wrappers/ace目录下 ,新建 config.h 文件加入以下内容: #include " ...

  6. AngularJS1

    Ⅰ.AngularJS的点点滴滴--引导   AngularJS已经被很多人像炒冷饭一样炒过啦,大部分都是直接复制官方文档没有说明一些注意事项,不过什么都要从头开始吧 ###页面引导实例化 * * * ...

  7. 用Python实现gmail邮箱服务,实现两个邮箱之间的绑定(上)

    一.本程序的起源 当我决定去中科院实习的时候,我给刘奎恩老师发了封邮件.我对此事是非常看重的,因此经常使用浏览器,打开gmail去查看刘老师有没有给我回复.因为gmail的新邮件推送的功能仅限于打开浏 ...

  8. Grub禁用UUID

    这个属于一个个人喜好问题,我每次看到 df -h 的结果都很郁闷,根目录那一行设备是用uuid表示的,那一串字符真是够长的,看起来非常别扭,所以就自己修改了一下/etc/default/grub文件. ...

  9. MDX示例:求解众数(mode)

    在统计学中,众数(Mode)是样本观测值在频数分布表中频数最多的那一组的组中值,主要应用于大面积普查研究之中,众数在一组数据中可能会有好几个.简单的说,众数就是一组数据中占比例最多的一个或几个数.MD ...

  10. Xcode5和ObjC新特性

    Welcome to Xcode 5 这是我的WWDC2013系列笔记中的一篇,完整的笔记列表请参看这篇总览.本文仅作为个人记录使用,也欢迎在许可协议范围内转载或使用,但是还烦请保留原文链接,谢谢您的 ...