python P3904 三只小猪

题面
题面所求即为第二类斯特林数

1
2
3
4
5
6
7
8
9
10
11
12
13
n, m = map(int, input().split(' '))
a = [[0] * 55 for _ in range(55)]
if(m > n):
print(0)
else:
for i in range(1, n + 1):
a[i][i] = a[i][1] = 1

for j in range(2, m + 1):
for i in range(j + 1, n + 1):
a[i][j] = a[i - 1][j - 1] + a[i - 1][j] * j

print(a[n][m])