백준 11050번 이항 계수 1
< 백준 11050번 이항 계수 1 - 마포 코딩박 >
사용한 알고리즘: 구현
순열조합의 nCk 를 구현하는 문제였습니다.
문제풀이는 다음과 같습니다.
(1) (코드 4~11)
nCk = n!/k!(n-k)! = n*(n-1)*...*(n-k+1) / k! 입니다.
입력되는 n 의 최대값이 10 으로 충분히 작으므로 위를 단순 계산해주는 함수를 만들었습니다.
사용한 알고리즘: 구현
순열조합의 nCk 를 구현하는 문제였습니다.
문제풀이는 다음과 같습니다.
(1) (코드 4~11)
nCk = n!/k!(n-k)! = n*(n-1)*...*(n-k+1) / k! 입니다.
입력되는 n 의 최대값이 10 으로 충분히 작으므로 위를 단순 계산해주는 함수를 만들었습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
int Combi(int n, int k){ | |
int temp1 = 1; | |
int temp2 = 1; | |
for(int i=n; i>n-k; i--) temp1*=i; | |
for(int i=1; i<=k; ++i) temp2*=i; | |
return temp1/temp2; | |
} | |
int main(){ios::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL); | |
int N, K; | |
cin >> N >> K; | |
cout << Combi(N,K) << '\n'; | |
return 0; | |
} |
댓글
댓글 쓰기
긴 글 읽어주셔서 감사합니다.
궁금한게 있으시다면 댓글 달아주세요!