为什么样例cnt输出10???
查看原帖
为什么样例cnt输出10???
297798
FANTA5TlC楼主2020/6/15 21:54
#include <bits/stdc++.h>
#define pi acos(-1)
//#define m 19260817
using namespace std;
int n, m;
int mx, my;
int cnt;
bool a[25][25];
bool v[25][25];
void dfs(int x, int y){
	if (x == n && y == m){
		++cnt;
//		cout << cnt << " ";
	}
	if (x > n || y > n) return;
	if (a[x][y] == true) return;
	if (v[x][y] == true) return;
	v[x][y] = true;
	dfs(x + 1, y);
	dfs(x, y + 1);
//	dfs(x - 1, y);
//	dfs(x, y - 1);
	v[x][y] = false;
}
int main(){
	ios::sync_with_stdio(false);
	cin >> n >> m >> mx >> my;
	if (mx + 1 <= n && my + 2 <= m) a[mx + 1][my + 2] = true;
	if (mx + 2 <= n && my + 1 <= m) a[mx + 2][my + 1] = true;
	if (mx - 1 >= 0 && my - 2 >= 0) a[mx - 1][my - 2] = true;
	if (mx - 2 >= 0 && my - 1 >= 0) a[mx - 2][my - 1] = true;
	if (mx - 2 >= 0 && my + 1 <= m) a[mx - 2][my + 1] = true;
	if (mx - 1 >= 0 && my + 2 <= m) a[mx - 1][my + 2] = true;
	if (mx + 1 <= n && my - 2 >= 0) a[mx + 1][my - 2] = true;
	if (mx + 2 <= n && my - 1 >= 0) a[mx + 2][my - 1] = true;
	dfs(0, 0);
	cout << cnt << endl;
}

2020/6/15 21:54
加载中...