๐Ÿ’  BOJ/Class 2

[BOJ][C++] ๋ฐฑ์ค€ 11050๋ฒˆ: ์ดํ•ญ ๊ณ„์ˆ˜ 1

์„ ๋‹ฌ 2023. 2. 28. 02:53
๋ฐ˜์‘ํ˜•

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

 

11050๋ฒˆ: ์ดํ•ญ ๊ณ„์ˆ˜ 1

์ฒซ์งธ ์ค„์— \(N\)๊ณผ \(K\)๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ \(N\) ≤ 10, 0 ≤ \(K\) ≤ \(N\))

www.acmicpc.net

 

๋ฌธ์ œ

์ž์—ฐ์ˆ˜ N๊ณผ ์ •์ˆ˜ K๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ ์ดํ•ญ ๊ณ„์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— N๊ณผ K๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ N ≤ 10, 0 ≤ K  N)

์ถœ๋ ฅ

๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

 

ํ’€์ด

#include <iostream>

using namespace std;

int factorial(int n) {
    int output = 1;
    for(int i=2; i<=n; i++) {
        output *= i;
    }
    return output;
}

int main() {
    ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    int n, k;
    cin >> n >> k;
    
    int denominator = factorial(n);
    int numerator = factorial(k)*factorial(n-k);
    
    cout << denominator/numerator;
    
    return 0;
}
๋ฐ˜์‘ํ˜•