#include <iostream>
using namespace std;
#define ll long long
const int C = 51;
ll dp[C][C][C][C];
ll a[C][C];
int main()
{
int n, m, i, j, ii, jj;
cin >> n >> m;
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
{
cin >> a[i][j];
a[i][j] += (a[i][j - 1] + a[i - 1][j] - a[i - 1][j - 1]);
for (ii = 1; ii <= n; ii++)
for (jj = 1; jj <= m; jj++)
dp[i][j][ii][jj] = 1e9;
}
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
dp[i][j][i][j] = 0;
for (int l = 1; l <= n + m - 2; l++)
for (int x1 = 1; x1 <= n; x1++)
for (int y1 = 1; y1 <= n; y1++)
for (int x2 = x1; x2 <= n && x2 - x1 <= l; x2++)
{
int y2 = y1 + (l - (x2 - x1));
ll x = a[x2][y2] + a[x1 - 1][y1 - 1] - a[x1 - 1][y2] - a[x2][y1 - 1];
for (i = x1; i < x2; i++)
dp[x1][y1][x2][y2] = min(dp[x1][y1][x2][y2], dp[x1][y1][i][y2] + dp[i + 1][y1][x2][y2] + x);
for (i = y1; i < y2; i++)
dp[x1][y1][x2][y2] = min(dp[x1][y1][x2][y2], dp[x1][y1][x2][i] + dp[x1][i + 1][x2][y2] + x);
}
cout << dp[1][1][n][m];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
3 ms |
2124 KB |
Output is correct |
8 |
Incorrect |
9 ms |
4888 KB |
Output isn't correct |
9 |
Correct |
27 ms |
7908 KB |
Output is correct |
10 |
Correct |
28 ms |
9036 KB |
Output is correct |
11 |
Incorrect |
16 ms |
7212 KB |
Output isn't correct |
12 |
Correct |
116 ms |
17340 KB |
Output is correct |
13 |
Correct |
239 ms |
22488 KB |
Output is correct |
14 |
Incorrect |
27 ms |
9068 KB |
Output isn't correct |
15 |
Correct |
289 ms |
25848 KB |
Output is correct |
16 |
Correct |
173 ms |
21512 KB |
Output is correct |
17 |
Correct |
386 ms |
29356 KB |
Output is correct |
18 |
Correct |
1033 ms |
43528 KB |
Output is correct |
19 |
Correct |
1347 ms |
48332 KB |
Output is correct |
20 |
Runtime error |
85 ms |
103912 KB |
Execution killed with signal 11 |