当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1223:DEHUFF

题目描述
A certain data compression technique involves creating a table of variable-length binary codes where one or more binary digits are used to represent a single letter of an alphabet. Usually, letters that occur most frequently in words
generated using this alphabet will have shorter binary codes than those used less frequently. For example, in an alphabet consisting of the letters A through Z, in general the letter E appears in more words than the letter Q;
therefore it would be expected that E would have a shorter binary code than does Q.
Given a sample string using at least one of each letter in an alphabet, along with the entire binary encoding of that sample string, you should be able to generate at least one binary code table for each letter in the alphabet. For
example, consider the sample string: "CAB" which contains each letter of the alphabet {A,B,C}. If the binary encoding of "CAB" is "01011" then the (only) binary code table is:
C = 0
A = 10
B = 11
The binary codes for each character are prefix codes in that no code in the set can be the initial binary string for any other code (so A = 01, B = 011 would not be allowed). For this problem, you will write a program that determines
binary code tables for sample strings and their binary encodings. If there is a single binary code table solution, then you will print it out (sorted). If more than one binary code table can be generated from the given set of data, you
will print "MULTIPLE TABLES". Note: For a given alphabet, the entire code space will be used; that is, there will be no unused codes.
输入解释
Input consists of a single line consisting of an integer value N representing the number of datasets that follow. Each dataset consists of two lines. The first line is the sample string that contains at least one of each letter (or space) in
the alphabet. The second line is the binary encoding of the sample string. Note: Sample strings may only contain upper case letters and spaces.
输出解释
For each dataset, print a line that identifies the dataset in the format: "DATASET #n" where n is the dataset number (1 through N). If more than one binary code table can be generated to represent the alphabet, print "MULTIPLE TABLES" on a new line and move onto the next dataset. If only one binary code table can be generated, for each character in the alphabet, display the letter, a space, and equal sign (=), a space and the binary code for that letter.
Display the table in order sorted by the ASCII value of each character of the alphabet.
输入样例
3
CAB
01011
HELLO WORLD
111011011110111101111100111111111111011111101111010
ABCDEFGHI
010110111011110111110111111011111110001011111111
输出样例
DATASET #1
A = 10
B = 11
C = 0
DATASET #2
  = 0
D = 10
E = 110
H = 1110
L = 11110
O = 111110
R = 1111110
W = 1111111
DATASET #3
MULTIPLE TABLES

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 Greater New York 2002

源链接: POJ-1223

最后修改于 2020-10-29T05:58:07+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
3000 65536