2238

HfjNUlYZ

a睿
bcwing
3I算法训练

ZnSO4
shengshu_
TSFH
itdef

hznode
Kim_6
iKUNの少轩
ohhhdddentist
DZDdzd

https://www.luogu.com.cn/problem/P1101
xdm能帮我看看这个搜索吗，我用深搜一直没写对😥😥😥😥😥😥

🙋 🙋 ✍️✍️✍️✍️✍️

🙋 🙋 ✍️✍️✍️✍️✍️

int dx[]={-1,0,1,0},dy[]={0,1,0,-1};

https://www.luogu.com.cn/problem/AT_dfs_a

#include <iostream>

using namespace std;

const int N = 510;
int n, m;

bool st[N][N];

char g[N][N];

int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };
//家 鱼店
int xa, ya, xb, yb;

bool dfs(int x, int y)
{
if (x == xb && y == yb) return true;

if (g[x][y] == '#') return false;
st[x][y] = true;
for (int i = 0; i < 4; i++)
{
int a = x + dx[i], b = y + dy[i];
if (a < 0 || a >= n || b < 0 || b >= n)
continue;
if (st[a][b]) continue;
if (dfs(a, b)) return true;

}
return false;

}

int main()
{
cin >> n >> m;

for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
cin >> g[i][j];
if (g[i][j] == 's')
{
xa = i;
ya = j;
}
if (g[i][j] == 'g')
{
xb = i;
ya = j;
}
}

if (dfs(xa, ya)) cout << "Yes";
else cout << "No" ;
return 0;
}



xdm，这题暴搜怎么写呀
https://www.luogu.com.cn/problem/P2089#submit

#include <iostream>

using namespace std;
const int N =15;
int cnt;
int state[N];
int st[4]={0,1,2,3};
int n;
//第i个配料 美味程度
void dfs(int u,int dels)
{
if(u> 10){
if(dels == n)
{
for(int i =1;i<=n;i++) cout << state[i] << ' ';
cout << endl;
return;
}
}
for(int i =1;i<= n;i++ )
{
//枚举配料
for(int j = 1;j<=3;j++)
{
state[u] = st[j];

if(dels > n) break;
dfs(u+1,dels+ st[j]);
state[u] = 0;
return;
}
}

}

int main()
{
//输入美味程度
cin >> n;

dfs(1,n);
}



https://www.luogu.com.cn/problem/solution/P1002