这题比之前做的搜索题水很多,根本不用标记,因为每次走不同的地方,都不会返回,蚂蚁只能向上或友行
这里转换了一下,题目是从左下角到右上角,我求的是左上角到右下角,结果是一样地~
#include<iostream>
using namespace std;
int m, n;
int count = 0;
void dfs(int , int);
int main()
{
//freopen("C:\\Users\\Haojian\\Desktop\\test.txt", "r", stdin);
while (cin >> m >> n)
{
count = 0;
dfs(0,0);
cout << count << endl;
}
return 0;
}
void dfs (int x, int y)
{
if (x == m-1 && y == n-1)
{
count++;
return;
}
else
{
if (x+1 < m && y < n)
dfs(x+1, y);
if (x < m && y + 1 < n)
dfs(x, y+1);
}
}