https://www.acmicpc.net/problem/2163
min 함수 쓸라면 #include<algorithm> 하면 됨!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include<iostream> #include<cstring> #include<algorithm> using namespace std; const int MAX = 300; int n, m; int cache[MAX + 1][MAX + 1]; int DP(int x, int y) { if (x == 1 && y == 1) return 0; int& ret = cache[x][y]; if (ret != -1) return ret; ret = n * m - 1; for (int i = 1; i < x; i++) { ret = min(ret, DP(x - i, y) + DP(i, y) + 1); } for (int i = 1; i < y; i++) ret = min(ret, DP(x, y - i) + DP(x, i) + 1); return ret; } int main() { cin >> n >> m; memset(cache, -1, sizeof(cache)); cout << DP(n, m) << endl; return 0; } | cs |
'알고리즘 > BOJ' 카테고리의 다른 글
2644 촌수계산 BFS (성공) (0) | 2018.02.20 |
---|---|
4963 섬의개수 DFS (코드만) (0) | 2018.02.20 |
2662 기업투자 DP (코드만) (0) | 2018.02.20 |
1987 알파벳 (성공) (0) | 2018.02.19 |
1987 알파벳 (실패) (0) | 2018.02.19 |