蒟蒻求助,样例输出55
查看原帖
蒟蒻求助,样例输出55
604622
achjuncool楼主2022/6/3 20:37

是我写的搜索有问题吗

#include <iostream>
using namespace std;
int n, m, a[19][19], total;
int xx[5] = {0, 1, 2, 2, 1};
int yy[5] = {0, -2, -1, 1, 2};
void search(int x, int y){
	for(int i = 1; i <= 4; i++){
		int nx = x + xx[i];
		int ny = y + yy[i];
		if(nx <= m && ny <= n && ny >= 0){
			if(nx == m && ny == n){
				total++;
			} else {
				search(nx, ny);
			}
		}
	}
}
int main(){
	cin >> n >> m;
	n++; m++;
	search(1, 1);
	cout << total << endl;
	return 0;
}
2022/6/3 20:37
加载中...