Protocols
InterviewTime limit3sMemory limit128 MB
Count the length-m strings over k symbols with no run of l equal symbols, then output floor((n/m) * log2(count)).
- Level
Medium5 of 10
- Topics
- Dynamic programming, Combinatorics, Math, Implementation
- Solved
- No attempts yet
Problem
A telecommunications company is designing a protocol to send data between two computers over a new cable. The cable can carry signals at different voltage levels, but the voltage may change only every of a second. Such a -second interval, during which the voltage stays constant, is called an impulse.
Data are sent in packets of consecutive impulses, so transmitting one packet takes seconds.
For technical reasons the voltage may not stay constant for too long inside a packet: a packet may not contain consecutive impulses at the same voltage level.
If a protocol can send different packets, then each packet carries bits of information. The task is to find how many bits of information can be sent in one second.
For example, suppose the cable offers voltage levels (), written and . Let the voltage change times per second (), let each packet contain impulses (), and let no consecutive impulses share the same level (). Then the packets , , , , and cannot be sent, while , , , , , , , , and can. Since different packets are available, each packet carries bits. In one second packets are sent, giving bits of information.
Write a program that reads the integers , , and describing the protocol, computes the maximum number of bits of information that can be sent in one second, and prints that number rounded down to the nearest integer.
Input
The first line contains four integers separated by single spaces:
- the number of voltage levels (),
- the impulse frequency (),
- the packet size (),
- the forbidden run length (): a packet may not contain consecutive impulses at the same voltage level.
It is guaranteed that is an integer not greater than .
Output
Print a single integer: the maximum number of bits of information that can be sent in one second, rounded down to the nearest integer.