编程介的小学生 2017-03-05 11:28 采纳率: 20.5%
浏览 723
已采纳

Dehuff

ZOJ Problem Set - 1355
Dehuff
Time Limit: 10 Seconds Memory Limit: 32768 KB
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

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.

Output

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.

Sample Input

3
CAB
01011
HELLO WORLD
111011011110111101111100111111111111011111101111010
ABCDEFGHI
010110111011110111110111111011111110001011111111

Sample Output

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

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-03-10 23:04
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题