Tight Words
InterviewTime limit1sMemory limit128 MB
Count words of length n over digits 0..k where adjacent digits differ by at most 1, then print that count as a percentage rounded to five decimals.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Combinatorics, Math, Implementation
- Solved
- No attempts yet
Problem
Consider the alphabet where . A word of length over this alphabet is called tight if every pair of neighbouring digits differs by at most .
Input
The input consists of several lines. Each line contains two integers and (, ). Process each line in order until the end of input (EOF).
Output
For each input line, print the percentage of tight words of length over the alphabet . That is, the number of tight words divided by the total number of words , multiplied by . Print the value rounded to exactly fractional digits (ties, i.e. , round up).