2018-10-27 16:57:32 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
def p(n,k):
|
|
|
|
if k == 0:
|
|
|
|
return 0
|
|
|
|
elif n == k or k == 1:
|
|
|
|
return 1
|
|
|
|
elif n < k:
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
return p(n-1,k-1) + p(n-k,k)
|
|
|
|
|
|
|
|
def s(n,k):
|
|
|
|
if n == k:
|
|
|
|
return 1
|
|
|
|
elif k == 0:
|
|
|
|
return 0
|
|
|
|
elif n < k:
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
return s(n-1,k-1) + (n-1)*s(n-1,k)
|
|
|
|
|
|
|
|
def S(n, k):
|
|
|
|
if n == k:
|
2018-10-28 13:23:03 +01:00
|
|
|
return " S_{" + n + "," + k + "} "
|
|
|
|
# return 1
|
2018-10-27 16:57:32 +02:00
|
|
|
elif k == 1:
|
2018-10-28 13:23:03 +01:00
|
|
|
return " S_{" + n + "," + k + "} "
|
|
|
|
# return 1
|
2018-10-27 16:57:32 +02:00
|
|
|
elif k == 0:
|
2018-10-28 13:23:03 +01:00
|
|
|
return " S_{" + n + "," + k + "} "
|
|
|
|
# return 0
|
2018-10-27 16:57:32 +02:00
|
|
|
elif n < k:
|
2018-10-28 13:23:03 +01:00
|
|
|
return " S_{" + n + "," + k + "} "
|
|
|
|
# return 0
|
2018-10-27 16:57:32 +02:00
|
|
|
else:
|
2018-10-28 13:23:03 +01:00
|
|
|
return " S_{" + str(n-1) + "," + str(k-1) + "} + " + str(k) + " * S_{" + str(n-1) + "," + str(k) + "} "
|
|
|
|
# return S(n-1,k-1) + k * S(n-1,k)
|
2018-10-27 16:57:32 +02:00
|
|
|
|
2018-10-28 13:23:03 +01:00
|
|
|
print(S(5,3))
|
|
|
|
# print(p(10,4))
|