【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 ...
随机推荐
- 【Flutter学习】基本组件之BottomNavigationBar底部导航栏
一,概述 BottomNavigationBar即是底部导航栏控件,显示在页面底部的设计控件,用于在试图切换,底部导航栏包含多个标签.图标或者两者搭配的形式,简而言之提供了顶级视图之间的快速导航. 二 ...
- ldap yum安装-centos6
yum安装openldap 系统环境信息 操作系统:CentOS release 6.7 基础的环境准备 iptables -F && /etc/init.d/iptables sav ...
- IOS 随笔记录
一.IOS 关闭键盘: 1.让所有控件的键盘隐藏 // 这个方法可以让整个view取消第一响应者,从而让所有控件的键盘隐藏 [self.view endEditing:YES]; 2.让某个textF ...
- 【转】理解JMX之介绍和简单使用
原文链接:https://blog.csdn.net/lmy86263/article/details/71037316 近期在项目上需要添加一些功能,想把一个开源工程整合进来,虽说是整合,但是觉得跟 ...
- Prometheus 详解
Prometheus 章节 1.Prometheus 简介 2.Prometheus 安装与配置 3.Exporter 4.Pushgateway 5.本地存储和远程存储 6.高可用方案 7.报警插件 ...
- 高级UI晋升之自定义View实战(九)
更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680 1.前言: 本文采用自定义view的方法来实现一键清除的动画这个功能. 2.效果 ...
- Octave的安装
本文是参考吴恩达老师的深度学习视频而做的笔记 深度学习 引言 挑战:AI真正的挑战在于解决那些对人类来说很容易执行,但很难形式化描述的问题,比如识别人们所说的话/图像中的脸/分辨苹果和梨. 解决方案: ...
- spring3+structs2整合hibernate4时报org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void sy.dao.impl.UserDaoImpl.setSessionFactory(org.hibernate.SessionFactory);
今天在spring3+structs2整合hibernate4时报如下错误,一直找不到原因: org.springframework.beans.factory.BeanCreationExcepti ...
- 判断list中元素是否是相邻
private static List<Integer> findShunZi(List<Integer> tmpCards){ List<Integer> lis ...
- 杭电多校第四场-H- K-th Closest Distance
题目描述 You have an array: a1, a2, , an and you must answer for some queries.For each query, you are g ...