|
发表于 2024-2-22 10:23:46
|
显示全部楼层
问题:尺度过大
试一下我修改后的吧- #include <iostream>
- #include <cstring>
- using namespace std;
- int n,m,h;
- int startx,starty,endx,endy;
- int a[10001][10001];
- int vis[10001][10001];
- int xx[4] = {1,0,-1,0};
- int yy[4] = {0,1,0,-1};
- bool yes = false;
- void dfs(int x,int y,int xue)
- {
- if(xue>=h or yes)
- {
- return;
- }
- else if(x==endx and y==endy)
- {
- cout << "Yes" << '\n';
- yes = true;
- return;
- }
- vis[x][y] = 1;
- for(int i = 0;i<4;i++)
- {
- int newx = x+xx[i];
- int newy = y+yy[i];
- if(newx>=1 and newx<=n and newy>=1 and newy<=m and vis[newx][newy]==0)
- {
- dfs(newx,newy,xue+a[newx][newy]);
- }
- }
- }
- int main()
- {
- cin.tie(0);
- cout.tie(0);
- ios::sync_with_stdio(0);
- int q;
- cin >> q;
- while(q--)
- {
- memset(vis,0,sizeof(vis));
- yes = false;
- cin >> n >> m >> h;
- for(int i = 1;i<=n;i++)
- {
- for(int j = 1;j<=m;j++)
- {
- char s;
- cin >> s;
- if(s=='S')
- {
- startx = i;
- starty = j;
- }
- else if(s=='T')
- {
- endx = i;
- endy = j;
- }
- else
- {
- a[i][j] = s-'0';
- }
- }
- }
- dfs(startx,starty,0);
- if(not yes)
- {
- cout << "No" << "\n";
- }
- }
- return 0;
- }
复制代码
给个最佳答案吧,求求了 |
|