Run ID | 作者 | 问题 | 语言 | 测评结果 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|
1256 | yy019 | 鸣人与佐助 | C++ | 运行超时 | 1000 MS | 280 KB | 781 | 2022-05-29 20:05:08 |
#include <bits/stdc++.h> using namespace std; int m,n,t,tmp,mx,my,minstep=1e5; char c[205][205]; bool b[205][205]; int d[][2]={{-1,0}, {0,1}, {1,0}, {0,-1}}; //int steps[205][205][11]; void dfs(int x,int y,int t,int step){ if(x<1||x>n||y<1||y>m||b[x][y]) return; if(t<0) return; if(step>=minstep) return; // steps[x][y][t]=step; if(c[x][y]=='#') t--; if(c[x][y]=='+'){ if(step<minstep) minstep=step; return; } b[x][y]=true; for(int i=0;i<4;i++){ dfs(x+d[i][0],y+d[i][1],t,step+1); } b[x][y]=false; } int main(){ cin>>m>>n>>t; for(int i=1;i<=m;i++){ for(int j=1;j<=n;j++){ cin>>c[i][j]; if(c[i][j]=='@'){ mx=i,my=j; } } } dfs(mx,my,t,0); if(minstep==1e5) cout<<-1; else cout<<minstep; return 0; }