棋盘、格子路径等问题用dfs

#include<iostream>
using namespace std;
int cnt;
int m, n;
void dfs(int row, int col)
{
    if (row == m && col == n )/*终止条件,找到设定点*/
    {
        cnt++;
        return;
    }
    if (row <m+1 && col <n+1)/*递归条件,不能超出边界,注意m*n其实划线来看是有(m+1)*(n+1)个数*/
    {
        dfs(row + 1, col);
        dfs(row , col+1);
    }
}

int main()
{
    while (cin >> m >> n)
    {
        dfs(0, 0);
        cout << cnt << endl;
        cnt = 0;
    }
}