Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Django
- 7576번
- 1010번: 다리 놓기 (Python)
- 백준 1158번
- 고속거듭제곱알고리즘
- 백준 1158
- max_length
- 경상국립대학교
- epsp
- lgh
- 5397
- 문제풀이
- NaverCloudPlatform
- 백준 토마토
- 다리 놓기
- PS
- linc3.0
- 백준 다리놓기
- python
- ncloud서버
- ncp배포
- Charfield
- 그래프 탐색
- 백준
- 16953
- 백준 7576
- 요세푸스 문제
- 9735번
- 백준 7576번
- json
Archives
- Today
- Total
DolphinDash
백준 1010번: 다리 놓기 (Python) 본문
처음에 봤을 때 막막했는데 경우의 수를 나열했을 때 익숙한 숫자 배열이여서 조합인걸 알았다. 그래서 조합을 사용해서 코드를 짜 봤는데,
import itertools
N = int(input())
for i in range(N):
a, b = map(int, input().split())
nCr = itertools.combinations([f"{i}" for i in range(b)], a)
print(len(list(nCr)))
오른쪽 다리의 최대 갯수가 30개인걸 생각하면 조합을 사용해서는 시간 초과가 나올 것이 분명해서 그냥 식을 써봤다.
import sys
sys.getrecursionlimit = 1000000
N = int(input())
def nCr(n, r):
return (fac(n) // fac(r)) // fac(n-r)
def fac(num):
if num <= 1: return 1
return fac(num - 1) * num
for i in range(N):
a, b = map(int, input().split())
print(nCr(b, a))
nCr = n! / (n-r)! * r! 이니 그대로 옮겨서 함수로 구현해 봤다.
'PS > Solve' 카테고리의 다른 글
백준 7576번: 토마토 (Python) (0) | 2023.06.28 |
---|---|
백준 1158번: 요세푸스 문제 (Python) (0) | 2023.05.23 |
백준 1991번: 트리 순회 (Python) (0) | 2023.05.20 |
백준 16953번: A → B (Python) (0) | 2023.05.19 |
백준 1629번: 곱셈 (Python) (0) | 2023.04.06 |