====== 有多少个5位递减数? ======
===== 问题 =====
A decreasing number is a number where each digit is less than the digit to its left. For example, 87420 is a decreasing number.
How many five digit decreasing numbers are there?
===== 解 =====
这是一道典型的排列组合问题。首先,由于递减数的定义是高位比低位数字要大,令该数字为overline{abcde},满足a>b、b>c、c>d、d>e,这样我们需要取5个不同的数字。在0-9这10个数字中选取5个不同的数字之后,其从大到小的排列方式是唯一的,因而这个问题就转化成了在10个数字中任意选取5个数字有多少种组合的问题。
我们知道:n C r = {n!} / {r!(n-r)!}
由于 n=10 而 r=5,得到:
10 C 5 = {10!} / {5!(10-5)!}
10 C 5 = {10*9*8*7*6*5*4*3*2*1} / {{(5*4*3*2*1)*(5*4*3*2*1)}}
10 C 5 = {10*9*8*7*6} / {{5*4*3*2*1}}
10 C 5 = {2*9*2*7*2} / {{2*1}}
10 C 5 = {2*9*2*7}
10 C 5 = 252
因此一共有252个。
写个 Python 脚本验证一下:
total = 0
for x in range(43210,98765+1):
a, b, c, d, e = str(x)
if (a > b) and (b > c) and (c > d) and (d > e):
total = total + 1
print(total)