BOJ 11051 c++

Algorithm / / 2020. 7. 17. 18:59

BOJ 11051 c++ 이항계수 2

백준 11051 c++ 이항계수 2


풀이 1.


#include <bits/stdc++.h>
using namespace std;

int n, k;
int d[1005][1005];

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

    cin >> n >> k;
    d[0][0] = 1;
    d[0][1] = 0;
    for (int i = 1; i <= n; i++) {
        for(int j = 0; j <= i; j++) {
            d[i][j] = (d[i-1][j] + d[i-1][j-1]) % 10007;
        }
    }
    cout << d[n][k];
    return 0;
}

풀이 2.


#include <bits/stdc++.h>
using namespace std;

int n, k;
int d[1005][1005];

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

    for (int i = 1; i <= 1000; i++) {
        d[i][i] = 1;
        d[i][0] = 1;
        for(int j = 1; j < i; j++) {
            d[i][j] = (d[i-1][j] + d[i-1][j-1]) % 10007;
        }
    }
    cin >> n >> k;
    cout << d[n][k];
    return 0;
}

분류 : 수학


'Algorithm' 카테고리의 다른 글

BOJ 11653 c++  (0) 2020.07.17
BOJ 2501 c++  (0) 2020.07.17
BOJ 11050 c++ 이항계수(1)  (0) 2020.07.17
BOJ 1931 c++  (0) 2020.07.16
BOJ 11047 c++  (0) 2020.07.16
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기
// custom