【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 ...
随机推荐
- 【leetcode】945. Minimum Increment to Make Array Unique
题目如下: Given an array of integers A, a move consists of choosing any A[i], and incrementing it by 1. ...
- linux su su-的区别
su只是切换用户. su - 切换用户并切换shell环境. su another pwd后为/home/current su - another pwd后为/home/another
- IDEA入门使用--二
*)IDEA安装和破解:https://www.cnblogs.com/jajian/p/7989032.html 这次我安装的是最新版2019的IDEA *)导入项目时,根据提示,一步步来.其 ...
- (转)Jupyter默认目录和默认浏览器修改
目录 1.总结:修改Anaconda中的Jupyter Notebook默认工作路径的三种方式 # 2.Jupyter默认目录和默认浏览器修改 1.总结:修改Anaconda中的Jupyter Not ...
- 学习Spring时用Idea中Maven Project创建一个子module出现了子pom.xml没有继承父pom.xml
正常情况: 解决方法: 1.首先点击父项目右键 -->new-->Module 2.不用点击create from achetype直接点击next 3.在ArtifactId输入你要mo ...
- uoj175 【Goodbye Yiwei】新年的网警
题目 胡乱分析 不妨定谣言的源头得到谣言的时刻为\(1\),那么其他人听到谣言的时间就是源头到这个点的最短路 假设\(i\)是谣言的源头,那么如果存在一个点\(j\)满足\(\forall k\in[ ...
- zabbix--ODBC 监控mysql
zabbix ODBC 数据库监控ODBC 是 C 语言开发的.用于访问数据库的中间件接口.zabbix 支持查询任何 ODBC 支持的数据库.zabbix 通过调用ODBC 来获取数据库的数据以及数 ...
- v-distpicker 一个好用的三级联动的插件
// 引入插件npm install v-distpicker --save import VDistpicker from 'v-distpicker' Vue.component('v-distp ...
- Pytest conftest共享数据及不同层次共享
数据共享:在 conftest.py配置里写方 法可以实现数据共享, 不需要import导入.可 以跨文件共享 1.建立一个新的文件,文件名必须叫"conftest.py",然后写 ...
- 从URL输入到页面展现,过程中发生了什么?
从在地址栏中输入了URL,到浏览器展现出页面整个过程中,大概经历了如下过程: 在浏览器地址中输入了URL并回车 域名解析 服务器处理请求 浏览器处理 网页的绘制 一.在浏览器地址中输入URL 首先解释 ...