본문 바로가기
알고리즘/DP

2163 초콜릿 자르기

by tryotto 2019. 2. 7.
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
#include <stdio.h>
 
using namespace std;
 
int cache[400][400= { 0 };
 
int dp(int y, int x) {
    int& ret = cache[y][x];
 
    if (x == 1 && y == 1return 0;
 
    if (ret != 0return ret;
    if (y == 1) {
        ret = dp(y, x / 2+ dp(y,x- x / 2+ 1;
    }
    else {
        ret = dp(y / 2, x) + dp(y-/ 2 , x) + 1;
    }
 
    return cache[y][x];
}
 
int main() {
    int n, m;
    scanf("%d %d"&n, &m);
    getchar();
 
    printf("%d", dp(n, m));
}
cs


'알고리즘 > DP' 카테고리의 다른 글

1932 정수삼각형 (숫자 삼각형 더블릿)  (0) 2019.02.07
1010 다리놓기  (0) 2019.02.07
9465 스티커  (0) 2019.02.07
11727 타일(2)  (0) 2019.02.07
11726 타일(1)  (0) 2019.02.07