#include<bits/stdc++.h>
using namespace std;
int n,x;
int a[101][101];
bool dfs(int x,int y,int p)
{
if(x<1||y<1||x>n||y>n)return 0;
p-=a[x][y];
if(p<=0)return 0;
if(x==n&&y==n)return 1;
else return dfs(x-1,y,p)||dfs(x+1,y,p)||dfs(x,y+1,p)||dfs(x,y-1,p);
}
int main()
{
cin>>n>>x;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin>>a[i][j];
if(dfs(1,1,x))cout<<"YES";
else cout<<"NO";
return 0;
}
题目:这个比赛中的C题,邀请码4x1d求大佬帮帮忙
有人说用双重循环搜索,我怎么听不懂呢