BOJ::2407 조합

시사점

이해(x)

설계, 손 코딩(x)

시간 복잡도

공간 복잡도

손 코딩 후 문제 리뷰(x)

구현(x)

함수 List

업데이트 되는 변수

실제 구현

#include<bits/stdc++.h>
#define endl '\n'
#define se second
#define fi first
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;
typedef unsigned long long ll;

string dp[100+2][100+2];
string add(string a, string b){
    string s = "";
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    if(a.size() > b.size()) swap(a, b);
    int carry = 0;
    int diff = (int)(b.size() - a.size());
    rep(i, 0, diff) a+='0';
    rep(i, 0, a.size()){
        int sum = (a[i]-'0') + (b[i]-'0') + carry;
        carry = sum/10;
        s += sum%10+'0';
    }
    if(carry) s += carry+'0';
    reverse(s.begin(), s.end());
    return s;
}
void process(){
    int n, k;
    cin >> n >> k;
    dp[1][1] = "1";
    rep(i, 2, n+2){
        rep(j, 1, i+1){
            dp[i][j] = add(dp[i-1][j-1], dp[i-1][j]);
        }
    }
    cout << dp[n+1][k+1] << endl;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    process();
    return 0;
}

구현 후 코드리뷰 + 예제 돌려보기(x)

디버깅(x)

좋은 코드

최적화