当前位置:网站首页>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),也就是递归输出的终止点。
边栏推荐
猜你喜欢

Puyuan Jingdian turned losses into profits in the first half of the year, and high-end products continued to develop!Are you optimistic about "Huawei" in the instrument industry?

Word箭头上面怎么打字

FS4066耐高压1到4节内置MOS的锂电池充电管理芯片

Unity2D_背景粒子效果

Prometheus Operator 自定义监控添加redis explorer

【图文并茂】如何进行Win7系统的重装

【泛型编程】模板全详解

数据集成API如何成为企业数字化转型的关键?

tki-tree 树组件控制默认展开第几层数据

2.3 监督学习-2
随机推荐
Prometheus Operator 通过additional 添加target
Error when source install/setup.bash
cadence中复制一部分PCB到另一个PCB中去
Interviewer: How to deal with Redis big key?
阿里二面:没有 accept,能建立 TCP 连接吗?
linux定时执行sql文件[通俗易懂]
LED闪烁 闪灯芯片IC 手电筒IC 闪灯控制IC 闪烁IC流水灯
Can I make a TCP connection without accept?
2.3 监督学习-2
一种基于连接和安全熵的网络空间整体安全认识和方法
安科瑞支持以太网通讯、profibus通讯嵌入式电能表APM指导性技术要求-Susie 周
力扣15-三数之和——HashSet&双指针法
fixed investment fund
普源精电上半年扭亏为盈,高端产品持续发力!你看好仪器界“华为”吗?
哪款C语言编译器(IDE)适合初学者?
Word第一页不要页眉怎么设置?设置Word首页不要页眉方法教程
How to fix Windows 11 not finding files
URL Protocol web page to open the application
什么是IDE(集成开发环境)?
10个 Istio 流量管理 最常用的例子,你知道几个?