#include <iostream>
#include <vector>
using namespace std;
int prefix[31][31];
// il, ir, jl, jr
int dp[31][31][31][31];
int solve(int const il, int const ir, int const jl, int const jr) {
if (ir - il == -1 || jr - jl == -1) {
return 0;
}
int& ans = dp[il][ir][jl][jr];
if (ans != 0) {
return ans;
}
auto const sum = [&](int const il, int const ir, int const jl, int const jr) {
return prefix[ir + 1][jr + 1] - prefix[il][jr + 1] - prefix[ir + 1][jl] + prefix[il][jl];
};
auto const opponent = [&](int const il, int const ir, int const jl, int const jr) {
return sum(il, ir, jl, jr) - solve(il, ir, jl, jr);
};
int const top = opponent(il + 1, ir, jl, jr) + sum(il, il, jl, jr);
int const bottom = opponent(il, ir - 1, jl, jr) + sum(ir, ir, jl, jr);
int const left = opponent(il, ir, jl + 1, jr) + sum(il, ir, jl, jl);
int const right = opponent(il, ir, jl, jr - 1) + sum(il, ir, jr, jr);
return ans = max({ top, bottom, left, right });
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
prefix[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
prefix[i + 1][j + 1] = prefix[i][j + 1] + prefix[i + 1][j] - prefix[i][j] + a[i][j];
}
}
int const ans = solve(0, n - 1, 0, m - 1);
cout << ans << "\n";
//for (int isize = n; isize >= 1; isize--) {
// for (int jsize = n; jsize >= 1; jsize--) {
// for (int il = 0; il + isize - 1 < n; il++) {
// int const ir = il + isize - 1;
// for (int jl = 0; jl + jsize - 1 < m; jl++) {
// int const jr = jl + jsize - 1;
// // top
// dp[il + 1][ir][jl][jr] = opponent(il, ir, jl, jr) + sum(il, il, jl, jr);
// }
// }
// }
//}
}
Forditási hiba
exit status 1
main.cs(2,0): error CS1024: Wrong preproces