Topic Link:
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=124
Type: Hash
Original title:
Perfect Software, INC has obtained a government contract to examine text flowing through a high-speed network for the OCC Urrence of certain words. Your boss, Wally Perfect, has designed a parallel processing system which checks each word against a group of small perfec T hash tables.
A perfect hash function maps its input directly to a fully occupied table. The Your job is to construct the perfect hash functions from the lists of words into each table. The hash function is the form
, where C is a positive integer for you are to discover, W was an integer representation of ' an ' input word, and n is the length of the table. C must be as small as possible. Note that
is the floor function and this is the largest integer.
Here are Wally ' s notes on the subject:
Let
consist of positive integers
. The problem is to find the smallest positive integer C such that
For all
.
C must be a multiple the at least one element of W.
If some
For all
,
Then the next largest C that could resolve the conflict are at least
Since all such conflicts must being resolved, it is advantageous to choose the largest candidate the among as The next C to test.
You are are to convert each of word to a and by processing the from left to right. Consider ' a ' to is 1, ' B ' to be 2,
, ' Z ' to be 26. Use 5 bits for each letter (shift left by 5 or multiply by 32). Thus ' A ' = 1, ' BZ ' =
.