这个代码有什么问题吗(请针对我的代码)
查看原帖
这个代码有什么问题吗(请针对我的代码)
731250
Silencer_jin楼主2023/11/1 13:00
#include<bits/stdc++.h>
using namespace std;
int t,n,m,maxx=INT_MIN,ans,a[10][10];
bool vis[10][10];
void dfs(int x,int y){
	if(y>m){
		dfs(x+1,1);
		return;
	}
	if(x>n){
		maxx=max(maxx,ans);
		return;
	}
	dfs(x,y+1);
	if(vis[x][y]==false){
		ans+=a[x][y];
		vis[x-1][y-1]=true;
		vis[x-1][y]=true;
		vis[x-1][y+1]=true;
		vis[x][y-1]=true;
		vis[x][y+1]=true;
		vis[x+1][y-1]=true;
		vis[x+1][y]=true;
		vis[x+1][y+1]=true;
		dfs(x,y+1);
		vis[x-1][y-1]=false;
		vis[x-1][y]=false;
		vis[x-1][y+1]=false;
		vis[x][y-1]=false;
		vis[x][y+1]=false;
		vis[x+1][y-1]=false;
		vis[x+1][y]=false;
		vis[x+1][y+1]=false;
		ans-=a[x][y];
	}
}
int main(){
	cin >> t;
	for(int k=1;k<=t;k++){
		memset(a,0,sizeof(a));
		memset(vis,false,sizeof(vis));
		cin >> n >> m;
		for(int i=1;i<=n;i++)
		    for(int j=1;j<=m;j++)cin >> a[i][j];
		ans=0;
		dfs(1,1);
		cout << ans << endl;
	}
	return 0;
}
2023/11/1 13:00
加载中...