【hihocoder 1554】最短的 Nore0061
【链接】http://hihocoder.com/problemset/problem/1554
【题意】
【题解】
【错的次数】
【反思】
【代码】
- #include <bits/stdc++.h>
- using namespace std;
- #define lson l,m,rt<<1
- #define rson m+1,r,rt<<1|1
- #define LL long long
- #define rep1(i,a,b) for (int i = a;i <= b;i++)
- #define rep2(i,a,b) for (int i = a;i >= b;i--)
- #define mp make_pair
- #define pb push_back
- #define fi first
- #define se second
- #define ms(x,y) memset(x,y,sizeof x)
- #define ri(x) scanf("%d",&x)
- #define rl(x) scanf("%lld",&x)
- #define rs(x) scanf("%s",x+1)
- #define oi(x) printf("%d",x)
- #define ol(x) printf("%lld",x)
- #define oc putchar(' ')
- #define os(x) printf(x)
- #define all(x) x.begin(),x.end()
- #define Open() freopen("F:\\rush.txt","r",stdin)
- #define Close() ios::sync_with_stdio(0)
- typedef pair<int,int> pii;
- typedef pair<LL,LL> pll;
- const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
- const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
- const double pi = acos(-1.0);
- const int N1 = 100;
- const int N2 = 3000;
- const int INF = 0x3f3f3f3f;
- char a[N1+10],b[N1+10],s[N2+10];
- int lena,lenb,f[2][N1+10][N1+10];
- int main(){
- //Open();
- //Close();
- rs(a);
- rs(b);
- rs(s);
- lena = strlen(a+1),lenb = strlen(b+1);
- int n = strlen(s+1);
- ms(f[0],INF);
- f[0][0][0] = 0;
- int ans = -1;
- rep1(i,1,n){
- int now = i&1,pre = now^1;
- ms(f[now],INF);
- f[now][0][0] = 0;
- rep1(j,0,lena)
- rep1(k,0,lenb)
- if (f[pre][j][k]<INF){
- f[now][j][k] = min(f[pre][j][k] + 1,
- f[now][j][k]);
- if (s[i] == a[j+1]){
- f[now][j+1][k] = min(f[now][j+1][k],
- f[pre][j][k]+1);
- }
- if (s[i] == b[k+1]){
- f[now][j][k+1] = min(f[now][j][k+1],
- f[pre][j][k]+1);
- }
- }
- int tans = f[now][lena][lenb];
- if (tans >= INF) continue;
- if (ans==-1 || tans < ans){
- ans = tans;
- }
- }
- oi(ans);puts("");
- return 0;
- }
【hihocoder 1554】最短的 Nore0061的更多相关文章
- hihocoder 1931 最短管道距离
描述 在一张2D地图上有N座城市,坐标依次是(X1, Y1), (X2, Y2), ... (XN, YN). 现在H国要修建一条平行于X轴的天然气主管道.这条管道非常长,可以认为是一条平行于X轴的直 ...
- hihocoder 1829 - 压缩字符串 - [状压+暴力枚举][2018ICPC北京网络预赛B题]
题目链接:https://hihocoder.com/problemset/problem/1829 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Lara Croft, ...
- hihocoder 1485----hiho字符串
hihocoder 1485:hiho字符串 描述 如果一个字符串恰好包含2个'h'.1个'i'和1个'o',我们就称这个字符串是hiho字符串. 例如"oihateher".&q ...
- hihoCoder #1320 : 压缩字符串 区间dp
/** 题目:hihoCoder #1320 : 压缩字符串 链接:https://hihocoder.com/problemset/problem/1320 描述 小Hi希望压缩一个只包含大写字母' ...
- hihocoder 后缀自动机专题
一.后缀自动机基本概念的理解 1.首先后缀自动机的状态是由子串的endpos来决定的 子串的endpos是指一个子串可以在原字符串的哪些位置进行匹配, endpos构成的不同集合划分成不同的状态 关于 ...
- 【hihocoder 1473】小Ho的强迫症
[题目链接]:http://hihocoder.com/problemset/problem/1473 [题意] [题解] 假定初始为在在0位置(相对它左边那条线); 则考虑; 多少步之后,人又能这到 ...
- 北京2018网络赛 hihocoder#1828 : Saving Tang Monk II (BFS + DP +多开一维)
hihocoder 1828 :https://hihocoder.com/problemset/problem/1828 学习参考:https://www.cnblogs.com/tobyw/p/9 ...
- [LeetCode] Minimum Unique Word Abbreviation 最短的独一无二的单词缩写
A string such as "word" contains the following abbreviations: ["word", "1or ...
- [LeetCode] Shortest Word Distance III 最短单词距离之三
This is a follow up of Shortest Word Distance. The only difference is now word1 could be the same as ...
随机推荐
- Concurrent - 多线程
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11426916.html Java中有几种方法可以实现一个线程? 继承Thread类(不支持多继承) 实 ...
- 小鱼易连 for mac如何使用?小鱼易连 mac版使用教程
小鱼易连 for mac如何使用?小鱼易连 mac版是参加远程会议人士的首选,高效极致,简单流畅,视频流畅,语音清晰,无需专用网络的功能深受用户的喜欢,它提供的文件和电脑的共享,让你的会议更加高效.下 ...
- &与&&、|与||的区别
&和&& 相同之处: &和&&都表示:符号两端必须同时为真,最后的结果才为真:其中一端为假,则最后的结果为假 不同之处: &:左端为假,还需要继 ...
- bind-dns服务器搭建
环境:主服务器上IP为192.168.159.30 安装相关包bind dns服务器 bind-utils提供nslookup dig等命令 yum -y install bind bind-uti ...
- tomcat7以下线程控制
web server允许的最大线程连接数还受制于操作系统的内核参数设置,通常Windows是2000个左右,Linux是1000个左右. 1.编辑tomcat安装目录下的conf目录下的server. ...
- SQL语句映射文件(2)增删改查、参数、缓存
2.2 select 一个select 元素非常简单.例如: <!-- 查询学生,根据id --> <select id="getStudent" paramet ...
- TIOBE 编程语言排行榜是什么,它是如何计算编程语言排行的?
做为一名程序员,都比较关注其使用编程语言的热度,一方面编程语言的热度决定了它拥有多大的市场,另一方面也关系到行业内程序员选择机会有多大. 我们总听说某个编程语言排名第一,那么这些数据到底准不准确呢? ...
- 通过angular.js实现MVC的基本步骤
通过ng实现MVC的基本步骤: ①创建模块 var app = angular.module('模块名字',['依赖模块1','依赖模块2']) ②调用模块 ngApp--> ng-app=&q ...
- Prometheus 详解
Prometheus 章节 1.Prometheus 简介 2.Prometheus 安装与配置 3.Exporter 4.Pushgateway 5.本地存储和远程存储 6.高可用方案 7.报警插件 ...
- vue事件修饰符(once:prev:stop)
vue事件修饰符(once:prev:stop) stop修饰符 效果如下: 当你鼠标在这个div里的时候,x与y的值:会随着鼠标的变化而变化.但是当鼠标放在stopMoving的时候,x与y的值是 ...