蓝桥杯和天梯赛都有一个搜索题,气死偶嘞!
P2392 kkksc03考前临时抱佛脚
1st
数据范围小,直接暴搜
2nd
P1036 [NOIP2002 普及组] 选数
1st
在判断满足条件后return结束递归。。。记得写
2nd
特判1
P2036 [COCI2008-2009#2] PERKET
1st
对于题目中至少添加一种调料的特判:
- 如果选到最后还是初始的参数,说明啥玩意也没选,return
P1101 单词方阵
struct nod
{
int xx, yy;
};
vector<nod> qu;
void dfs(int x, int y, int fx, int fy, int pos)
{
if (x < 1 || x > n || y < 1 || y > n) return;
if (a[x][y] == s[pos])
{
qu.push_back({x, y});
if (pos == 6)
{
for (auto &tmp : qu)
b[tmp.xx][tmp.yy] = 1;
qu.clear();
return;
}
}
else
{
qu.clear();
return;
}
if (fx == 0 && fy == 0)
for (int i = 0; i < 8; i++)
dfs(x, y, dx[i], dy[i], pos );
else
dfs(x + fx, y + fy, fx, fy, pos + 1);
}
1st
第一次错在忘写不满足条件的return。
2nd
在对于初始点的判断,向八个方向搜索,递归应该以
(初始点,方向,下标)
为起始点,而非
(下一个点,方向,下一个下标)