Catalan number - Wikipedia
From Wikipedia, the free encyclopedia Jump to navigation Jump to search Recursive integer sequence In combinatorial mathematics, the Catalan numbers form a sequence of natural numbers that occur in various counting problems, often involving recursively def
en.wikipedia.org
카탈랑 수(Catalan number)란?
Cn = 2n! / n! (n+1)! 형태의 점화식을 갖는 수열로 조합론에서 꽤 빈번하게 등장한다고 한다.
따라서 카탈랑 수를 python 코드로 구현할 경우 아래와 같다.
import math
num = int(input())
def catalan(n):
return math.factorial(2 * n) // (math.factorial(n) * math.factorial(n + 1))
print(catalan(num))
'algorithm' 카테고리의 다른 글
[python] 후위 표기식 계산 알고리즘 (0) | 2021.07.21 |
---|---|
[python] 모듈로 구현하는 큐(Queue) (0) | 2021.07.14 |
[python] 리스트로 구현하는 스택과 큐 (0) | 2021.07.13 |