这题不是动规吗,搜索没动规好写不加记忆化还超时
by AKIOI官方账号 @ 2020-05-16 20:55:17
@[jbzns3ndn](/user/318876) 说明您强
by impuk @ 2020-05-16 20:55:34
@[AKIOI官方账号](/user/344528) 刚学,只会深搜,帮我看看为什么一次就结束呗,大佬
by 金城武 @ 2020-05-16 20:56:46
@[Zhaoyuhang2008](/user/242524)
> 搜你horse
可不能骂人啊……
这题可以搜索过的(当然要加上记忆化)
by impuk @ 2020-05-16 20:57:05
@[Zhaoyuhang2008](/user/242524) 骂人?
by Trinitrotoluene @ 2020-05-16 20:57:11
@[一只爬行者](/user/279700) 搜所记忆化=dp循环改递归
by JRzyh @ 2020-05-16 20:58:19
```
#include <iostream>
using namespace std;
int a[21][21] = { 0 },s=0, ne[8][2] , step = 0, book[21][21] = { 0 }, i, j, k, sum;
int n, m, c, d;
void dfs(int x, int y)
{
int tx, ty;
int next[2][2] = {
{0,1},{1,0}};
if (x == n && y == m)
{
sum++;
return;
}
for (k = 0; k <2; k++)
{
tx = x + next[k][0];
ty = y + next[k][1];
if (tx<0 || tx>n || ty<0 || ty>m )
continue;
for (i = 0; i < 8; i++)
{
if ((tx == ne[i][0] &&ty == ne[i][1]))
{
s++;
}
}
if (s == 1)
continue;
s=0;
if (book[tx][ty] == 0)
{
book[tx][ty] = 1;
dfs(tx, ty);
book[tx][ty] = 0;
}
}
}
int main()
{
cin >> n >> m;
cin >> c >> d;
int ne[8][2] = { {c + 2,d + 1},{c + 1,d + 2},{c - 1,d + 2},{c - 2,d + 1},{c - 2,d - 1},{c - 1,d - 2},{c + 1,d - 2},{c + 2,d - 1} };
book[0][0] = 1;
dfs(0,0);
cout << sum;
}
```
改一下刚才的代码
by 金城武 @ 2020-05-16 20:58:31
初学者,不知道问题出在哪
by 金城武 @ 2020-05-16 20:59:21
@[Zhaoyuhang2008](/user/242524)
> 搜**所**记忆化=dp循环改递归
不不不,这俩东西不一样的。
by impuk @ 2020-05-16 20:59:29
我只想知道为什么一次就结束了,其他的我慢慢改吧
by 金城武 @ 2020-05-16 21:00:01