실버2 : 동적계획법 문제이다.

Code

//
//  main.cpp
//  algorithm_prac
//
//  Created by 최완식 on 2021/04/05.
//
 
#include <iostream>
using namespace std;
int dp[101][101][101] = {0,};
 
int w(int a, int b, int c){
    if (dp[a+50][b+50][c+50] != 0) {
        return dp[a+50][b+50][c+50];
    }
    
    if (a <= 0 || b <= 0 || c <= 0) {
        dp[a+50][b+50][c+50] = 1;
        return dp[a+50][b+50][c+50];
    }
    
    if (a > 20 || b > 20 || c > 20) {
        dp[a+50][b+50][c+50] = w(20, 20, 20);
        return dp[a+50][b+50][c+50];
    }
    
    if (a < b && b < c) {
        dp[a+50][b+50][c+50] = w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c);
        return dp[a+50][b+50][c+50];
    }
    
    dp[a+50][b+50][c+50] = w(a-1, b, c) + w(a-1, b-1, c) + w(a-1, b, c-1) - w(a-1, b-1, c-1);
    return dp[a+50][b+50][c+50];
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int a, b, c;
    
    while (true) {
        cin >> a >> b >> c;
        if (a == -1 && b == -1 && c == -1) break;
        cout << "w(" << a << ", " << b << ", " << c << ") = " << w(a, b, c) << '\n';
    }
    
    
    return 0;
}
 
}
 
 

Reference