蓝桥杯国赛白给记
A310电脑就离谱,明年去北京再战吧
持续更新ing
最后一道填空题:
hp DFS
#include<bits/stdc++.h>
using namespace std;
int N;
bool vis[6][6];
int ans = 0;
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
bool check() {
	for(int i = 1; i <= N; ++i) {
		for(int j = 1; j <= N; ++j) {
			if(!vis[i][j]) {
				return 0;
			}
		}
	}
	return 1;
}
void DFS(int x, int y) {
	//cout << x << " " << y << endl;
	if(x <= 0 || y <= 0 || x > N || y > N) {
		return;
	}
	if(check()) {
		ans++;
		return;
	}
	for(int i = 0; i < 4; ++i) {
		int xx = x + dir[i][0];
		int yy = y + dir[i][1];
		if(!vis[xx][yy]) {
			vis[xx][yy] = 1;
			DFS(xx, yy);
			vis[xx][yy] = 0;			
		}
	}
}
int main () {
	while(cin >> N) {
		ans = 0;
		memset(vis, 0, sizeof vis);
		for(int i = 1; i <= N; ++i) {
			for(int j = 1; j <= N; ++j) {
				memset(vis, 0, sizeof vis);
				vis[i][j] = 1;
				DFS(i, j);
			}
		}
		cout << ans << endl;		
	}
}
经验:用notepad配环境或者用命令行直接编译运行(g++ sbA310.cpp -> a.exe)死循环ctrl c终止
    作者:LightAc  
出处:https://www.cnblogs.com/lightac/  
联系:
Email: dzz@stu.ouc.edu.cn  
QQ: 1171613053
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。 

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号