| #1 | AC |
|---|
| #2 | MLE |
| #3 | MLE |
| #4 | AC |
| #5 | MLE |
| #6 | WA |
| #7 | WA |
| #8 | MLE |
| #9 | WA |
| #10 | WA |
| #11 | MLE |
感觉没问题,为什么会这样啊……
#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;
}