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. Input is a sequence of lines, each line contains two integer numbers k and n, 1 <= n <= 100. For each line of input, output the percentage of tight words of length n over the alphabet {0, 1, ... , k} with 5 fractional digits. 谢谢!

解决方案 »

  1.   

    现在给出一个数字符号集合 {0, 1, ... , k}, 0 <= k <= 9 .一个用这个集合中元素构造的长度为n的单词(暂且说成单词吧,其实是个数字串),如果其任何相邻数字差值都不超过1,我们就说这个单词是紧凑的。输入分许多行,每行包含两个整数k和n (1 <= n <= 100)针对每一行进行计算,输出基于{0, 1, ... , k}数字集合且长度为n的紧凑单词所占单词总数的百分比,精确到小数点后5位
    做acm是挺费思虑的~