当前位置:网站首页>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),也就是递归输出的终止点。
边栏推荐
- Interviewer: How to deal with Redis big key?
- Number of daffodils within a thousand
- matlab 神经网络 ANN 分类
- hdu 3341 Lost's revenge(dp+Ac自动机)
- 面试官:Redis 大 key 要如何处理?
- linux定时执行sql文件[通俗易懂]
- What to do if Windows 11 can't find Internet Explorer
- 字节一面:TCP 和 UDP 可以使用同一个端口吗?
- URL Protocol 网页打开应用程序
- DSPE-PEG-Silane, DSPE-PEG-SIL, phospholipid-polyethylene glycol-silane modified silica particles
猜你喜欢
leetcode 二叉树的分层遍历1
Word怎么制作一张标准的答题卡?
CMake 安装升级更高版本
Cholesterol-PEG-Thiol, CLS-PEG-SH, Cholesterol-PEG-Sulfhydryl for improved solubility
Can I make a TCP connection without accept?
Word怎么制作双面席卡?使用Word制作双面席卡方法
Skywalking系列学习之Trace Profiling源码分析
Problems with compiling SIP with QGIS
加工制造业智慧采购系统解决方案:助力企业实现全流程采购一体化协同
Lyapp exponents and bifurcation diagrams for fractional chaotic systems
随机推荐
安科瑞无线物联网智能电表ADW300指导性技术要求-Susie 周
Unity_物体自转
数据集成API如何成为企业数字化转型的关键?
Word文档怎么输入无穷大符号∞
【高效工具】远程控制软件 ToDesk(收藏夹)
力扣383-赎金信——哈希映射数组法
真香|持一建证书央企可破格录取
微软Excel表格点击单元格行和列都显示颜色怎么弄?聚光灯效果设置
WPF中加载并使用图像资源
继承关系下构造方法的访问特点
字节一面:TCP 和 UDP 可以使用同一个端口吗?
蓝牙模块的分类和对应的属性特点
Win11找不到Internet Explore怎么办
10个 Istio 流量管理 最常用的例子,你知道几个?
Redis 大的情况下,key 要如何处理?
力扣15-三数之和——HashSet&双指针法
How to fix Windows 11 not finding files
CMake 安装升级更高版本
Access Characteristics of Constructor under Inheritance Relationship
基于Docker构建MySQL主从复制数据库