高手进 关于英语编程的

来源:百度知道 编辑:UC知道 时间:2024/05/11 16:10:16
Consider the text “AAAAABCD”. Using ASCII, encoding this would require 64 bits. If, instead, we encode “A” with the bit pattern “00”, “B” with “01”, “C” with “10”, and “D” with “11” then we can encode this text in only 16 bits; the resulting bit pattern would be “0000000000011011”. This is still a fixed-length encoding, however; we’re using two bits per glyph instead of eight. Since the glyph “A” occurs with greater frequency, could we do better by encoding it with fewer bits? In fact we can, but in order to maintain a prefix-free encoding, some of the other bit patterns will become longer than two bits. An optimal encoding is to encode “A” with “0”, “B” with “10”, “C” with “110”, and “D” with “111”. (This is clearly not the only optimal encoding, as it is obvious that the encodings for B, C and D could be interchanged freely for any given encoding without increasing the size of the final encoded message.) Using this encoding, the message encodes in only 13 bits to “0000010110111”, a c

考虑文本“ aaaaabcd ” 。您使用ASCII ,编码这将需要64位。如果,相反,我们编码的“ A ”与位元模式“ 00 ” , “ B ”类与“ 01 ” , “ C ”类与“ 10 ” ,和“ D ”与“ 11 ”那么我们可以进行编码,这一案文只有16钻头;由此产生的位模式将是“ 0000000000011011 ” 。这仍是一个固定长度的编码,但是,我们正在使用的2 bits每字形,而非8 。由于字形的“ A ” ,就会发生更大的频率,我们可以做的更好的编码,它与少位?事实上,我们可以,但为了维持一个前缀-免费的编码,一些其他的位模式将成为长于2位。 1最优编码是编码的“ A ”与“ 0 ” , “乙”与“ 10 ” , “ C ”类与“ 110 ” ,和“ D ”与“ 111 ” 。(这显然不是唯一的最优编码,因为这是很明显,该编码为B , C和D可以自由互换对于任何给定的编码没有增加的大小最终编码的邮件。)使用这一编码,信息编码在只有13位“ 0000010110111 ” ,压缩比4.9至1 (即,每个位,在最后编码的邮件代表尽可能多的信息没有4.9钻头在原来的编码)。通读这位模式由左到右,你会看到,该前缀的免费编码,使简单的解码到这一点的原文,即使守则有不同的位长度。

作为第二个例子,考虑文本“猫在帽子” 。在这方面的文字,字母“ T ”和空间的性质都发生频率最高的,所以他们会显然有最短的编码位模式,在优化编码。字母的“ C ” , “我'与” N “只出现一次,但是,他们将有最长的代码。
有很多可能的套前缀免费可变长度的位模式将产生最优的编码,即是这将使文字编码,在最少的双边投资协定的数量。这样一个最优的编码是编码位与“ 00 ” , “一”与“ 100 ” , “ C ”类与“ 1110 ” , “电子”与“ 1111 ” , “ H ”型与“ 110 ” , “我”与“ 1010年“ , ” N “代表” 1011 “和”吨“与” 01 “ 。最优编码,因此只需要51位相比, 144个将要进行编码的信息,与8位的ASCII编码,压缩比为2.8比1 。
投入
输入文件将包含清单的文本字符串,每行一个。该文本字符串将只包括大写字母数字字符和下划线(这是用在地方的空格) 。年底投入