#include<bits/stdc++.h>
using namespace std;
int ans,v[1000][1000],tot,n,m,g[1000][1000];
int d[10][10]={{0,1,1,1,0,-1,-1,-1},{1,1,0,-1,-1,-1,0,1}};
void dfs(int x,int y)
{
if(ans<tot) ans=tot;
if(x==n) return;
if(!v[x][y])
{
tot+=g[x][y];
v[x][y]++;
for(int i=0;i<8;i++)
{
int nx=x+d[i][0],ny=y+d[i][1];
if(nx>=0&&nx<n&&ny>=0&&ny<m) v[nx][ny]++;
}
if(y+1<m) dfs(x,y+1);
else dfs(x+1,0);
tot-=g[x][y];
v[x][y]--;
for(int i=0;i<8;i++)
{
int nx=x+d[i][0],ny=y+d[i][1];
if(nx>=0&&nx<n&&ny>=0&&ny<m) v[nx][ny]--;
}
}
if(y+1<m) dfs(x,y+1);
else dfs(x+1,0);
}
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>v[i][j];
dfs(n,m);
cout<<ans<<endl;
}
return 0;
}
样例不对,求调(被卡好几个小时了,QAQ)