11599. Tight words
| ||
11599. Tight words
| ||
Description
Given is an alphabet {0, 1, ... , k}, 0 <= k <= 9 . We say that a word of length n over this alphabet is tight if any two neighbour digits in the word do not differ by more than 1. Your task is to find out the percentage of tight words of length n over the given alphabet.
Input
Input is a sequence of lines, each line contains two integer numbers k and n, 1 <= n <= 100.
Output
For each line of input, output the percentage of tight words of length n over the alphabet {0, 1, ... , k} with 5 fractional digits.
Sample Input
4 1 2 5 3 5 8 7
Sample Output
100.00000 40.74074 17.38281 0.10130 题意是用0到k这k+1个符号,组成一个n位的数,如果这个n位数相邻的位置上的数字差都不超过1,那么这个n位数就称为tight words,最后问tight words的个数占总数的百分比,因为总数有(k+1)^n之多,所以只能用double来存储了,我们用dp[i][j]表示i位数,最高位上是j的tight words的个数,初始化后,很容易就可以递推出来,因为个数比较大,long long也存不下,只能使用double了。 这道题目简单的数位dp,状态转移很简单,处理好边界就可以了。
|