|
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #define ri(x,a,b) for(register int x=a;x<=b;x++)
- using namespace std;
- int n,m,t,tx,ty,s;
- int mp[7][7],b[7][7];
- int dx[9]={0,0,1,1,1,0,-1,-1,-1};
- int dy[9]={0,1,-1,0,1,-1,0,-1,1};
- void ch(int x,int y,int sum)
- {
- if(x>m)s=max(s,sum);
- else if(y>n)ch(x+1,1,sum);
- else if(b[x][y])ch(x,y+1,sum);
- else
- {
- ri(i,1,8)
- {
- tx=x+dx[i];
- ty=y+dy[i];
- b[tx][ty]++;
- }
- ch(x,y+1,sum+mp[x][y]);
- ri(i,1,8)
- {
- tx=x+dx[i];
- ty=y+dy[i];
- b[tx][ty]--;
- }
- ch(x,y+1,sum);
- }
- }
- int main()
- {
- //freopen("qu.in","r",stdin);
- cin>>t;
- while(t--)
- {
- s=0;
- cin>>m>>n;
- memset(mp,0,sizeof(mp));
- memset(b,0,sizeof(b));
- ri(i,1,m)
- ri(j,1,n)
- cin>>mp[i][j];
- ch(1,1,0);
- cout<<s<<endl;
- }
- return 0;
- }
复制代码 |
|