博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu4271 Find Black Hand 2012长春网络赛E题 最短编辑距离
阅读量:5291 次
发布时间:2019-06-14

本文共 2852 字,大约阅读时间需要 9 分钟。

hdu4271 Find Black Hand  2012长春网络赛E题  最短编辑距离

Find Black Hand

Time Limit : 5000/2000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 19   Accepted Submission(s) : 1
Problem Description
I like playing game with my friends, although sometimes look pretty naive. Today I invent a new game called find black hand. The game is not about catching bad people but playing on a string.
Now I generate a string S and several short ones s[i], and I define three kinds of operations.
1. Delete: remove the ith character.
2. Insert: in any position, insert a character if you like.
3. Change: change the ith character into another character if you like.
For each short string s[i], we define a function f(i). After several operations on S, we can find a substring of S which is the same to s[i]. And f(i) is the minimal number of operations to achieve. It looks so native that I think every one of you can solve f(i) perfectly. So I join the string S from end to end, and f(i) changes nothing. So the string "bb" is also a substring of string "baaab".
The "black hand" is the short string s[i] whose f(i) is minimal. Now it's your time to find the black hand. 
 

 

Input
There are multiple test cases. The first line contains a non-empty string S whose length is not more than 100,000. The next line contains an integer N (1 <= N <= 10) indicating the number of the short string. Each of the next N lines contains a short non-empty string whose length is not more than 10. All strings in the input would not have blank and all characters are lower case.
 

 

Output
For each test case, output a string first indicating the "black hand", and then output an integer indicating the minimal number of the operation. If there are more than one "black hand", please output the smallest one in lexicographical order.
 

 

Sample Input
aaabbbb
2
alice
bob
 

 

Sample Output
bob 1
 

 

Source
2012 ACM/ICPC Asia Regional Changchun Online
 
#include
#include
#include
#include
#include
using namespace std;const int maxn=200100;const int INF=(1<<29);char s[maxn];char t[30][30];int n;int dp[30][maxn];int DP(char *t,char *s,int m,int n){ int res=INF; for(int i=0;i<=m;i++){ for(int j=0;j<=n;j++) dp[i][j]=0; } for(int i=1;i<=m;i++){ dp[i][0]=i; for(int j=1;j<=n;j++){ dp[i][j]=min(min(dp[i-1][j]+1,dp[i][j-1]+1),dp[i-1][j-1]+(t[i-1]!=s[j-1])); if(i==m) res=min(res,dp[i][j]); } } return res;}int main(){ freopen("in.txt","r",stdin); while(scanf("%s",s)!=EOF){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%s",t[i]); int len=strlen(s); int up=min(20,len); for(int i=0;i
View Code

 

 

转载于:https://www.cnblogs.com/--560/p/4781792.html

你可能感兴趣的文章
.NET Core 时代已经到了,你准备好了吗
查看>>
什么叫PV,UV,PR值
查看>>
Linux文件管理下
查看>>
SQL Server 事务隔离级别详解
查看>>
第9章 前端开发 口述题
查看>>
创建触发器
查看>>
django
查看>>
jquey常用代码
查看>>
Mac Mysql [ERR] 2006 - MySQL server has gone away
查看>>
OSG 3.40编译,osgQt编译失败解决方案
查看>>
[转载]web安全之token
查看>>
CNN的理解
查看>>
数据手册中Accuracy和Precision的准确定义
查看>>
2.5 定义FTP工具的各种方法
查看>>
linux命令
查看>>
PHP中XPATH 实现xml及html文件快速解析(附xml做小型数据库实现六级单词快速查询实例)...
查看>>
2017-2018-2 20155309 南皓芯 Exp9 Web安全基础
查看>>
Leetcode Reverse Words in a String
查看>>
一文读懂内网、公网和NAT
查看>>
NotMapped属性特性
查看>>