求助,五彩斑斓
查看原帖
求助,五彩斑斓
254389
_短笛无腔_楼主2021/8/8 11:59
#1AC
#2MLE
#3MLE
#4AC
#5MLE
#6WA
#7WA
#8MLE
#9WA
#10WA
#11MLE

感觉没问题,为什么会这样啊……

#include<bits/stdc++.h>
using namespace std;
int n,m,sum=-1,a[10][10];
void dfs(int x,int y,int hp,int step){
	if(x>n||x<1||y>m||y<1||a[x][y]==0||hp==0)return;
	if(a[x][y]==3){
		if(sum==-1)sum=step;
		else sum=min(sum,step);
		return;
	}
	if(a[x][y]==4)hp=6;
	dfs(x+1,y,hp-1,step+1);
	dfs(x-1,y,hp-1,step+1);
	dfs(x,y+1,hp-1,step+1);
	dfs(x,y-1,hp-1,step+1);
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)cin>>a[i][j];
	}
	dfs(1,1,6,0);
	cout<<sum;
	return 0;
}
2021/8/8 11:59
加载中...