파이썬 (56)
f=lambda n,k:k<1and 1or f(n-1,k-1)*n/k;print f(*input())
이진 계수를 계산하기위한 단축 코드 및 단축 법에 대한 설명이 있습니다. (참고 : 39 문자 버전으로 내려 가기 위해 아직 이해하지 못한 통찰력이 있습니다.이 접근법이 당신에게 도달 할 것이라고 생각하지 않습니다.)
# Since choose(n,k) =
#
# n!/((n-k)!k!)
#
# [n(n-1)...(n-k+1)][(n-k)...(1)]
# = -------------------------------
# [(n-k)...(1)][k(k-1)...(1)]
#
# We can cancel the terms:
#
# [(n-k)...(1)]
#
# as they appear both on top and bottom, leaving:
#
# n (n-1) (n-k+1)
# - ----- ... -------
# k (k-1) (1)
#
# which we might write as:
#
# choose(n,k) = 1, if k = 0
# = (n/k)*choose(n-1, k-1), otherwise
#
def choose(n,k):
if k < 1:
return 1
else:
return choose(n-1, k-1) * n/k
# input() evaluates the string it reads from stdin, so "5,2" becomes
# (5,2) with no further action required on our part.
#
# In the golfed version, we make use of the `*` unpacking operator,
# to unpack the tuple returned by input() directly into the arguments
# of f(), without the need for intermediate variables n, k at all.
#
n, k = input()
# This line is left as an exercise to the reader.
print choose(n, k)