这题比之前做的搜索题水很多,根本不用标记,因为每次走不同的地方,都不会返回,蚂蚁只能向上或友行

这里转换了一下,题目是从左下角到右上角,我求的是左上角到右下角,结果是一样地~

 

#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);
	}

}

相关文章:

  • 2021-10-10
  • 2021-07-30
  • 2021-10-22
  • 2021-07-27
  • 2021-12-19
  • 2021-10-05
  • 2022-03-05
  • 2021-09-29
猜你喜欢
  • 2021-06-03
  • 2022-12-23
  • 2021-08-23
  • 2021-08-29
  • 2022-02-27
  • 2021-10-27
  • 2021-08-02
相关资源
相似解决方案