当前位置:网站首页>hdu 1503 Advanced Fruits(最长公共子序列的应用)
hdu 1503 Advanced Fruits(最长公共子序列的应用)
2022-08-09 20:09:00 【51CTO】
题目: http://acm.hdu.edu.cn/showproblem.php?pid=1503
Advanced Fruits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2134 Accepted Submission(s): 1088
Special Judge
Problem Description
The company "21st Century Fruits" has specialized in creating new sorts of fruits by transferring genes from one fruit into the genome of another one. Most times this method doesn't work, but sometimes, in very rare cases, a new fruit emerges that tastes like a mixture between both of them.
A big topic of discussion inside the company is "How should the new creations be called?" A mixture between an apple and a pear could be called an apple-pear, of course, but this doesn't sound very interesting. The boss finally decides to use the shortest string that contains both names of the original fruits as sub-strings as the new name. For instance, "applear" contains "apple" and "pear" (APPLEar and apPlEAR), and there is no shorter string that has the same property.
A combination of a cranberry and a boysenberry would therefore be called a "boysecranberry" or a "craboysenberry", for example.
Your job is to write a program that computes such a shortest name for a combination of two given fruits. Your algorithm should be efficient, otherwise it is unlikely that it will execute in the alloted time for long fruit names.
Input
Each line of the input contains two strings that represent the names of the fruits that should be combined. All names have a maximum length of 100 and only consist of alphabetic characters.
Input is terminated by end of file.
Output
For each test case, output the shortest name of the resulting fruit on one line. If more than one shortest name is possible, any one is acceptable.
Sample Input
Sample Output
分析:大意,寻找包含两个字符串所有单个字符的最短字符串。

联想到最长公共子序列,输出那个寻找最长公共子序列的路径就是最小的最大串。
处理好边界,第0行全部指向左边,第0列全部指向上边,这样使得最终的汇聚点是(0,0),也就是递归输出的终止点。
边栏推荐
猜你喜欢

source install/setup.bash时出现错误

一千以内的水仙花数
![[Graphic and textual] How to reinstall Win7 system](/img/24/3acccb93e5e219f39477dc77229a58.png)
[Graphic and textual] How to reinstall Win7 system

UE4_定序器控制蓝图对象

buuctf (Adventure 2)

Word怎么制作一张标准的答题卡?

DSPE-PEG-Azide, DSPE-PEG-N3, phospholipid-polyethylene glycol-azide can react directly with DBCO

Win11搜索不到文件的解决方法

Jmeter 使用正则表达式提取器将返回值全部保存到一个文件中

安科瑞支持以太网通讯、profibus通讯嵌入式电能表APM指导性技术要求-Susie 周
随机推荐
Lyapp exponents and bifurcation diagrams for fractional chaotic systems
Interviewer: How to deal with Redis big key?
Ankerui supports Ethernet communication, profibus communication embedded energy meter APM guiding technical requirements-Susie Week
How to fix Windows 11 not finding files
Photometric Stereo 光度立体法三维重建
倍福CX5120实现温度控制例程详细解析
Error when source install/setup.bash
tki-tree 树组件控制默认展开第几层数据
Hessian Matrix 海森矩阵
Win11找不到Internet Explore怎么办
Word怎么制作一张标准的答题卡?
Word文档怎么输入无穷大符号∞
获取数组最后一项别再用array.length-1了
阿里二面:没有 accept,能建立 TCP 连接吗?
【Efficient Tools】Remote Control Software ToDesk (Favorites)
[corctf 2022] section
FET Mosfet Leiditech corresponds to Infineon Infineon
下秒数据:湖仓一体带来的现代数据堆栈变革开始了
【stack】【queue】【priority_queue】【deque】详解
MySQL笔记-06 基础SQL操作