Crossword.doc_第1页
Crossword.doc_第2页
Crossword.doc_第3页
Crossword.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

解题报告:Crossword题目来源:/ No.1709解法或类型:搜索作者:faononl CrosswordTime Limit:5S Memory Limit:2000KTotal Submit:99 Accepted:9 Description A double linear crossword of length L is a string of L lowercase alphabetic characters arranged in a line in such a way that there are at least two methods (so called decompositions) to split this string into the words from the given list. Look at the example for L=17: | | | |a n d a t a r e a l l a s t a s k | | | | |The words were taken from the following list: all, an, and, are, area, as, ask, at, data, last, or, read, real, task. The words from the first decomposition may not appear in the second one and vice versa. In addition, no word can be repeated in any decomposition. No word in one decomposition can end in the same place of the string where a word in the other composition ends, except, naturally, for the end of the string (otherwise the crossword can be separated into two independent crosswords). One of the compositions may consist of a single word. You should write a program to construct the first, in lexicographic order, double linear crossword of length L for a given list of words. Strings are arranged in the lexicographic order with respect of the following rules: If the first letter of a string appears in latin alphabet before the first letter of another string, then the former string precedes in lexicographic order. If the first letters of some strings match, then the corresponding letters of these strings are compared until they stop matching. If a mismatching is not found, the shorter string goes first. Input The first line of the input file consists of the single integer number L (4=L=50) denoting the desired crossword length. The second line consists of the single positive integer N (at most 1000) indicating the number of words in the list. Each of the followings N lines consists of a string of 20 or less (but at least 2) latin lowercase alphabetic characters. The words in the list are arranged in lexicographic order and no word is repeated. Output For the given input data set your program should write to the output file the first, in lexicographic order, double linear crossword with the given length. If it is impossible for the given input file to construct a double linear crossword with the given length, the program should write only the message NO SOLUTION (without the quotation marks). Sample Input 1719allanandareaasaskatdatadoforlastoforortreadrealtasktotorSample Output andatareadofortorSource Northeastern Europe 1997解题思路:这是一个搜索题看看这个例子, | | | |a n d a t a r e a l l a s t a s k | | | | |我的做法是构造两个字符串分别代表上面的划分和下面的划分,两个字符串长度较短的那个查找一个新的单词使之增加长度,直到找到一个满足长度要求的解。1) | a n 2) | a n d | 3) | | a n d a t a | 4) | |a n d a t a | | 5) | | a n d a t a r e | | | 6)在时间消耗上,每次查找能够匹配上一个单词多余部分的新单词消耗了大量时间。我考虑可以有几中选择。1, 顺序搜索2, 用散列表,构造散列函数实现,3, 构造二叉搜索树,(二分法)

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论