새소식

알고리즘/기타

[백준 2407] 조합 (파이썬 풀이)

  • -

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

 

2407번: 조합

n과 m이 주어진다. (5 ≤ n ≤ 100, 5 ≤ m ≤ 100, m ≤ n)

www.acmicpc.net

문제

nCm을 출력한다.

입력

n과 m이 주어진다. (5 ≤ n ≤ 100, 5 ≤ m ≤ 100, m ≤ n)

출력

nCm을 출력한다.

예제 입력 1

100 6

예제 출력 1

1192052400

제출 코드 1 (메모리 초과)

import sys
from itertools import combinations
input = sys.stdin.readline
n,m = map(int, input().split())
n_list = list(range(n))
print(len(list(combinations(n_list,m))))

제출 코드 2

import sys
from math import factorial
input = sys.stdin.readline
n,m = map(int, input().split())
x = factorial(n)
y = factorial(n-m)*factorial(m)
print(x//y)
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.