word rectangle
生活随笔
收集整理的這篇文章主要介紹了
word rectangle
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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存儲
總結
以上是生活随笔為你收集整理的word rectangle的全部內容,希望文章能夠幫你解決所遇到的問題。