๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 1010๋ฒˆ - ๋‹ค๋ฆฌ ๋†“๊ธฐ

by dkswnkk 2021. 10. 16.
 

1010๋ฒˆ: ๋‹ค๋ฆฌ ๋†“๊ธฐ

์ž…๋ ฅ์˜ ์ฒซ ์ค„์—๋Š” ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜ T๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๊ทธ ๋‹ค์Œ ์ค„๋ถ€ํ„ฐ ๊ฐ๊ฐ์˜ ํ…Œ์ŠคํŠธ์ผ€์ด์Šค์— ๋Œ€ํ•ด ๊ฐ•์˜ ์„œ์ชฝ๊ณผ ๋™์ชฝ์— ์žˆ๋Š” ์‚ฌ์ดํŠธ์˜ ๊ฐœ์ˆ˜ ์ •์ˆ˜ N, M (0 < N ≤ M < 30)์ด ์ฃผ์–ด์ง„๋‹ค.

www.acmicpc.net

 

//  Copyright © 2021 ์•ˆ์ฃผํ˜•. All rights reserved.
//  https://github.com/dkswnkk
//  https://www.acmicpc.net/problem/1010
//  BOJ1010 ๋‹ค๋ฆฌ ๋†“๊ธฐ

#include <iostream>
using namespace std;

int arr[31][31];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int T; cin>>T;
    while(T--){
        int N,M; cin>>N>>M;

        for(int i=0; i<=M; i++){
            for(int k=0; k<=N; k++){
                if(i==k||k==0) arr[i][k]=1;
                else{
                    arr[i][k]=arr[i-1][k-1]+arr[i-1][k];
                }
            }
        }
        cout<<arr[M][N]<<'\n';

    }
}

๋Œ“๊ธ€