word rectangle
生活随笔
收集整理的這篇文章主要介紹了
word rectangle
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
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,就是最長(zhǎng)單詞的平方。
然后
?for (z = max_rectangle to 1)
? ? ? ? ? for each pair of number (i,j) , where i*j = z
? ? ? ? ? ? ? ??
下面就是搜索的過(guò)程
主要原理就是,取得長(zhǎng)度為i的單詞列表當(dāng)做行,拿長(zhǎng)度為j的單詞列表當(dāng)做列
就是一個(gè)隊(duì)長(zhǎng)度為i的單詞列表的一個(gè)組合,使得列也能組成長(zhǎng)度為j的單詞,
長(zhǎng)度為j的單詞列表就可以用trie或者map存儲(chǔ)
總結(jié)
以上是生活随笔為你收集整理的word rectangle的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。