ACSL Practice 2009
You are asked to design a compression scheme for transmitting fax
images of documents. After an image is scanned in using a scanner, you
obtain a sequence of numbers where each number
Since it is not necessary to transmit the exact image, you decide to
discretize each number to
Level | ||||
---|---|---|---|---|
Code | 00 |
01 |
10 |
11 |
Then you realize that large areas of the same value (e.g. white) often occur in documents resulting in long sequences of very similar numbers. You decide to adopt a compression scheme as follows:
- For the first number in the sequence, you will use the
bits as described previously. - For all other numbers:
- if the previous number is the same as the current number, you
will transmit the bit
0
. - otherwise, you will transmit the bit
1
followed by the -bit code of the number. That is,1
followed by00
for number1
followed by01
for number1
followed by10
for number1
followed by11
for number
- if the previous number is the same as the current number, you
will transmit the bit
Finally, since you are not worried about a small amount of error, you
realize that you can improve your scheme by ignoring isolated changes.
For example, if the input sequence is 0000001011000
. If, instead you choose to transmit the
sequence 000000000
which is shorter.
You decide to measure the overall cost of a transmission by the following weighted sum
where
- the weight
can be adjusted to give more emphasis to either the total error or the total number of bits transmitted - for an input sequence
and a transmitted sequence , both of length , the total error is .
Example. For the input sequence
- we can transmit the sequence
by transmitting the string0000001011000
with a cost of ; - or we can transmit the sequence
by transmitting the string000000000
with a cost of .
In this case, the second option has lower cost.
Input Specification
The input consists of several lines. The first line contains two
integers
Output Specification
The output contains a single integer which is the smallest possible cost
required to transmit the input sequence with the given value of
Sample Input
8 100
2
2
2
2
2
46
2
2
Sample Output
952
Comments