搜索____深搜 学易错点

可直接看出:4行 5列 起点到终点步数为7(从0开始)

转化:转为只能往 → 与 ↓ 走的DFS

易错:dfs到下一个点,注意是判断 r+1 < ROW 而非 r < ROW

总结:题容易是容易,但是也要注意易错点与模型转化

#include <stdio.h>

#define ROW 5
#define COL 4
int count = 0;

void dfs(int r, int c, int n)
{
    if(n == 7)
    {
        count++;
        return;
    }
    if(r+1 < ROW)
        dfs(r+1, c, n+1);
    if(c+1 < COL)
        dfs(r, c+1, n+1);            
}

int main()
{
    dfs(0,0,0);
    printf("%d
", count);    
}
原文地址:https://www.cnblogs.com/wwjyt/p/3171336.html