Submission #28054

# Submission time Handle Problem Language Result Execution time Memory
28054 2017-07-15T06:29:22 Z undecember L 모양의 종이 자르기 (KOI15_cut) C++14
25 / 25
293 ms 28444 KB
#include <bits/stdc++.h>

using namespace std;

int ddp[51][51][51][51]; //h1, w1, h2, w2
int h1, w1, h2, w2;

int dp(int H, int W, int h, int w);

int main(void)
{
	scanf("%d%d%d%d", &h1, &w1, &h2, &w2);

	memset(ddp, -1, sizeof(ddp));

	printf("%d", dp(h1, w1, h2, w2));
	return 0;
}

int dp(int H, int W, int h, int w)
{
	if (ddp[H][W][h][w] >= 0) return ddp[H][W][h][w];
	if (h == 0 ^ w == 0) return dp(H, W, 0, 0);
	if (H == W && h == 0 && w == 0)
	{
		ddp[H][W][h][w] = 1;
		return 1;
	}

	int ans = INT_MAX;

	int i;
	for (i = 1; i < W - w; i++)
		ans = min(ans, dp(H, i, 0, 0) + dp(H, W - i, h, w));
	for (i; i < W; i++)
		ans = min(ans, dp(H, i, h, i - (W - w)) + dp(H - h, W - i, 0, 0));

	for (i = 1; i < H - h; i++)
		ans = min(ans, dp(i, W, 0, 0) + dp(H - i, W, h, w));
	for (i; i < H; i++)
		ans = min(ans, dp(i, W, i - (H - h), w) + dp(H - i, W - w, 0, 0));

	ddp[H][W][h][w] = ans;
	return ans;
}

Compilation message

cut.cpp: In function 'int dp(int, int, int, int)':
cut.cpp:23:8: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
  if (h == 0 ^ w == 0) return dp(H, W, 0, 0);
        ^
cut.cpp:35:8: warning: statement has no effect [-Wunused-value]
  for (i; i < W; i++)
        ^
cut.cpp:40:8: warning: statement has no effect [-Wunused-value]
  for (i; i < H; i++)
        ^
cut.cpp: In function 'int main()':
cut.cpp:12:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d%d", &h1, &w1, &h2, &w2);
                                       ^
# Verdict Execution time Memory Grader output
1 Correct 86 ms 28444 KB Output is correct
2 Correct 13 ms 28444 KB Output is correct
3 Correct 13 ms 28444 KB Output is correct
4 Correct 293 ms 28444 KB Output is correct
5 Correct 29 ms 28444 KB Output is correct
6 Correct 0 ms 28444 KB Output is correct
7 Correct 3 ms 28444 KB Output is correct
8 Correct 3 ms 28444 KB Output is correct
9 Correct 3 ms 28444 KB Output is correct
10 Correct 0 ms 28444 KB Output is correct
11 Correct 16 ms 28444 KB Output is correct
12 Correct 3 ms 28444 KB Output is correct
13 Correct 13 ms 28444 KB Output is correct
14 Correct 29 ms 28444 KB Output is correct
15 Correct 19 ms 28444 KB Output is correct
16 Correct 253 ms 28444 KB Output is correct
17 Correct 13 ms 28444 KB Output is correct
18 Correct 76 ms 28444 KB Output is correct
19 Correct 19 ms 28444 KB Output is correct
20 Correct 3 ms 28444 KB Output is correct