为什么vs2022能跑,洛谷就不行……
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
const int N = 20;
int cx[8] = { 1,1,1,0,0,-1,-1,-1 }, cy[8] = { 1,-1,0,-1,1,0,1,-1 };
int c = 0, select[N][N]{}, a[N][N]{};
static void matrix(int x, int y, int p, int n, int m)
{
if (y >= m)
{
y = 0;
x++;
}
if (x >= n)
{
c = max(c, p);
return;
}
if (select[x][y] == 0)
{
for (int i = 0; i < 8; i++)select[x + cx[i]][y + cy[i]]++;
matrix(x, y + 2, p + a[x][y], n, m);
for (int i = 0; i < 8; i++) select[x + cx[i]][y + cy[i]]--;
}
matrix(x, y + 1, p, n, m);
return;
}
int main()
{
int T, n, m;
cin >> T;
while (T--)
{
cin >> n >> m;
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> a[i][j];
memset(select, 0, sizeof(select));
c = 0;
matrix(0, 0, 0, n, m);
cout << c << endl;
}
return 0;
}