若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。


  • 运维

  • 前端

  • 编程

  • 随笔

  • hust-oj

1516: Doublets

发表于 2017-10-06   |   分类于 HUSTOJ   |   阅读次数 1,269

题目描述

A doublet is a pair of words that differ in exactly one letter; for example, “booster" and “rooster" or “rooster" and “roaster" or “roaster" and “roasted".

You are given a dictionary of up to 25,143 lowercase words, not exceeding 16 letters each. You are then given a number of pairs of words. For each pair of words, find the shortest sequence of words that begins with the first word and ends with the second, such that each pair of adjacent words is a doublet. For example, if you were given the input pair “booster" and “roasted", a possible solution would be (“booster," “rooster," “roaster," “roasted"), provided that these words are all in the dictionary.

输入

The input file contains the dictionary followed by a number of word pairs. The dictionary consists of a number of words, one per line, and is terminated by an empty line. The pairs of input words follow; each pair of words occurs on a line separated by a space.

输出

For each input pair, print a set of lines starting with the first word and ending with the last. Each pair of adjacent lines must be a doublet.
If there are several minimal solutions, any one will do. If there is no solution, print a line: “No solution.'' Leave a blank line between cases.

样例输入

booster
rooster
roaster
coasted
roasted
coastal
postal

booster roasted
coastal postal


样例输出

booster
rooster
roaster
roasted

No solution

参考代码

暂无

解析

暂无

hustoj

发表评论 取消回复

电子邮件地址不会被公开。 必填项已用*标注

*
*


hoxis wechat
著作权归作者所有
站点更新说明
  • 文章目录
  • 站点概览
若是凉夜已成梦

若是凉夜已成梦

青春里 总有些事情要努力去做 总有些梦想要拼命去追。

1904 日志
6 分类
12 标签
RSS
weibo github twitter facebook

友情链接

原站点 Dreams孤独患者 Skip
© 2017 若是凉夜已成梦
Powered by WordPress | 已运行
Theme By NexT.Mist