본문 바로가기
python-algorithm

백준 16395 파스칼의 삼각형

by 무적김두칠 2022. 10. 27.

https://www.acmicpc.net/problem/16395

 

16395번: 파스칼의 삼각형

파스칼의 삼각형은 이항계수를 삼각형 형태로 배열한 것인데, 블레즈 파스칼(1623-1662)을 따라 이름 붙여졌다. 단순한 형태로, 파스칼의 삼각형은 다음과 같은 방법으로 만들 수 있다. N번째 행

www.acmicpc.net

 

1
2
3
4
5
from math import factorial
n,k=map(int, input().split())
 
print(int(factorial(n-1)/(factorial(k-1)*factorial(n-1-(k-1)))))
 
cs

전형적인 DP 문제긴 한데.. 수학적으로 푸는게 더 빨라요
nCr = n!/ (r!*(n-r)!) 

This is typical Dynamic Programming problem,, but To solve mathematically is easier

반응형

'python-algorithm' 카테고리의 다른 글

백준 10174 팰린드롬  (0) 2022.10.27
백준 2635 수 이어가기  (0) 2022.10.27
백준 5613 계산기 프로그램  (0) 2022.10.26
백준 4447 좋은놈 나쁜놈  (0) 2022.10.26
백준 25784 Easy-to-Solve Expressions  (0) 2022.10.26

댓글