word rectangle

来源:互联网 发布:华网1588建站 编辑:程序博客网 时间:2024/05/16 04:17

Given a dictionary of millions of words, give an algorithm to find the largest possible rectangle of letters such that every row forms a word (reading left to right) and every column forms a word (reading top to bottom).


首先确定可能组成的最大矩形面积z,就是最长单词的平方。

然后

 for (z = max_rectangle to 1)

          for each pair of number (i,j) , where i*j = z

                


下面就是搜索的过程

主要原理就是,取得长度为i的单词列表当做行,拿长度为j的单词列表当做列


就是一个队长度为i的单词列表的一个组合,使得列也能组成长度为j的单词,

长度为j的单词列表就可以用trie或者map存储

原创粉丝点击