#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);
// }
// }
// }
//}
}
Compilation error
exit status 1
main.cpp: In function 'int solve(int, int, int, int)':
main.cpp:34:21: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
34 | return ans = max({ top, bottom, left, right });
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
from /usr/include/c++/11/ios:40,
from /usr/include/c++/11/ostream:38,
from /usr/include/c++/11/iostream:39,
from main.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
254 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: template argument deduction/substitution failed:
main.cpp:34:21: note: candidate expects 2 arguments, 1 provided
34 | return ans = max({ top, bottom, left, right });
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
I...