Idea: DP (x, y, K, h) represents a rectangle, the upper-left coordinate is (x, y), the width is k, and the length is H, so that the rectangle is cut into a minimum length of only one cake per block.
Simulated cut cake: horizontal cut, vertical cut, memory search can be.
AC Code
#include <cmath> #include <algorithm> #include <cstring> #include <utility> #include <string > #include <iostream> #include <map> #include <set> #include <vector> #include <queue> #
Include <stack> using namespace std; #pragma COMMENT (linker, "/stack:1024000000,1024000000") #define EPS 1e-10 #define INF 0x3f3f3f3f #define PI Pair<int,
int> typedef long Long LL;
const int MAXN = 20 + 2;
int D[MAXN][MAXN][MAXN][MAXN], CAKE[MAXN][MAXN];
int n, m, K;
int Count (int x, int y, int k, int h) {int cnt = 0;
for (int i = x, I < x + K; ++i) for (int j = y; J < y + H; ++j) {cnt + cake[i][j];
if (CNT >= 2) return 2;
} return CNT;
} int dfs (int x, int y, int k, int h) {int &ans = d[x][y][k][h];
if (ans! =-1) return ans;
int cnt = Count (x, Y, K, h);
if (cnt = = 1) return ans = 0;
else if (!cnt) return ans = inf;
ans = inf; Enumeration column for (int i = 1; i < H; ++i) {ans = min (ans, dfs (x, y, K, i) +dFS (x, Y+i, K, h-i) +k);
}//Pieces hold for (int i = 1; i < K; ++i) {ans = min (ans, dfs (x, y, I, h) +dfs (X+i, Y, K-i, h) +h);
} return ans;
} int main () {int kase = 1;
while (scanf ("%d%d%d", &n, &m, &k) = = 3) {memset (d,-1, sizeof (d));
memset (cake, 0, sizeof (cake));
int x, y;
for (int i = 0; i < K; ++i) {scanf ("%d%d", &x, &y);
Cake[x][y] = 1;
} printf ("Case%d:%d\n", kase++, DFS (1, 1, N, m));
} return 0; }
If there are any irregularities, please note.