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

建议使用的浏览器:

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

2880:Fixing Codes

题目描述
A binary string is a string of characters from the set {0, 1}. A code is a multiset of binary strings (i.e., a string can be repeated arbitrary number of times). A fixed code is a code that none of its strings is a prefix of another string. We say that a code A = {a1, a2, . . . , an} is extended to code B = {b1, b2, . . . , bn} if and only if for 1 <= i <= n, ai be a prefix of bi. The cost of this extension is __poj_jax_start__\sum_{i=1}^n|b_i|-|a_i|__poj_jax_end__ where |ai| is the number of characters in ai.

For this problem you are given a fixed code C, and a new binary string s. You have to find the minimum needed cost to extend the code C ∪ {s} into a fixed code. In other words, you are to append the minimum number of bits to zero or more codes in C ∪ {s} to make it a fixed code.
输入解释
The first line of the input contains a single integer t (1 ≤ t ≤ 20) which is the number of test cases in the input. For 1 ≤ i ≤ t the line i+1 consists a nonzero number of binary strings. The number of binary strings in each line is at most 41, and the length of each binary string is no more than 40 characters. The last string in each line stands for the new incoming string s and the other strings in that line make the fixed code of the relevant test case.

输出解释
The output consists m lines. The solution to ith test case should be written in the line i of the output.
输入样例
2
001 01 00
000 001 010 011 100 101 110 1
输出样例
1
2

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

题目来源 Tehran 2004

源链接: POJ-2880

最后修改于 2020-10-29T06:46:39+00:00 由爬虫自动更新

共提交 0

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