# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1040872 | lovrot | Raisins (IOI09_raisins) | C++17 | 53 ms | 25920 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <cstring>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long long ll;
const int N = 51;
const int OO = 0x7FFFFFFF;
int n, m;
int sum[N][N];
int dp[N][N][N][N];
int main() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
scanf("%d", &sum[i][j]);
sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
}
}
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
dp[i][j][i][j] = 0;
for(int k = i; k > 0; --k) {
for(int l = j - (k == i); l > 0; --l) {
int &d = dp[i][j][k][l] = OO;
for(int x = k; x < i; ++x) {
d = min(d, dp[i][j][x + 1][l] + dp[x][j][k][l]);
}
for(int y = l; y < j; ++y) {
d = min(d, dp[i][j][k][y + 1] + dp[i][y][k][l]);
}
d += sum[i][j] - sum[i][l - 1] - sum[k - 1][l] + sum[k - 1][l - 1];
// printf("%d %d %d %d : %d\n", i, j, k, l, dp[i][j][k][l]);
}
}
}
}
printf("%d\n", dp[n][m][1][1]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |