답안 #18862

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
18862 2016-02-16T05:39:10 Z Namnamseo L 모양의 종이 자르기 (KOI15_cut) C++14
25 / 25
232 ms 34128 KB
#include <cstdio>

int rectdp[51][51];
bool rectc[51][51];

int min(int a,int b){ return a>b?b:a; }

int rect(int w,int h){
    if(w==h) return 1;
    if(rectc[w][h]) return rectdp[w][h];
    rectc[w][h]=1;
    int& ret=rectdp[w][h];
    ret=1e9;
    int i;
    for(i=1; i<w; ++i) ret=min(ret, rect(i,h)+rect(w-i,h));
    for(i=1; i<h; ++i) ret=min(ret, rect(w,i)+rect(w,h-i));
    return ret;
}

bool chk[51][51][51][51];
int   dp[51][51][51][51];

int work(int a,int b,int c,int d){
    if(a==c) {
        if(b==d) return 1;
        else return rect(a, b-d);
    } else if(b==d){
        return rect(a-c,b);
    } else {
        int& ret=dp[a][b][c][d];
        if(chk[a][b][c][d]) return ret;
        chk[a][b][c][d]=1;
        ret=2e9;
        int i;
        for(i=1; i<=a-c; ++i) ret=min(ret, rect(i,b)+work(a-i,b,c,d));
        for(i=1; i<=b-d; ++i) ret=min(ret, rect(a,i)+work(a,b-i,c,d));
        for(i=1; i<c  ; ++i) ret=min(ret, rect(i,b-d)+work(a-i,b,c-i,d));
        for(i=1; i<d  ; ++i) ret=min(ret, rect(i,a-c)+work(a,b-i,c,d-i));
        return ret;
    }
}

int main()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    printf("%d\n",work(a,b,c,d));
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 34128 KB Output is correct
2 Correct 12 ms 34128 KB Output is correct
3 Correct 8 ms 34128 KB Output is correct
4 Correct 221 ms 34128 KB Output is correct
5 Correct 17 ms 34128 KB Output is correct
6 Correct 0 ms 34128 KB Output is correct
7 Correct 0 ms 34128 KB Output is correct
8 Correct 0 ms 34128 KB Output is correct
9 Correct 0 ms 34128 KB Output is correct
10 Correct 0 ms 34128 KB Output is correct
11 Correct 13 ms 34128 KB Output is correct
12 Correct 3 ms 34128 KB Output is correct
13 Correct 2 ms 34128 KB Output is correct
14 Correct 21 ms 34128 KB Output is correct
15 Correct 22 ms 34128 KB Output is correct
16 Correct 232 ms 34128 KB Output is correct
17 Correct 8 ms 34128 KB Output is correct
18 Correct 58 ms 34128 KB Output is correct
19 Correct 22 ms 34128 KB Output is correct
20 Correct 0 ms 34128 KB Output is correct