第八届蓝桥杯省赛C/C++B组 试题4:方格分割
作者:互联网
答案:509
#include <cstdio>
int ans = 0;
bool vis[10][10] = {false};
int X[4] = {1, -1, 0, 0};
int Y[4] = {0, 0, 1, -1};
void dfs(int x, int y){
if(x<=0 || x>=6 || y<=0 || y>=6){
ans++;
return;
}
for(int i=0; i<4; i++){
int tempX = x + X[i];
int tempY = y + Y[i];
if(!vis[tempX][tempY]){
vis[tempX][tempY] = vis[6-tempX][6-tempY] = true;
dfs(tempX,tempY);
vis[tempX][tempY] = vis[6-tempX][6-tempY] = false;
}
}
}
int main(){
vis[3][3] = true;
dfs(3,3);
printf("%d", ans/4);
return 0;
}
标签:int,C++,蓝桥,vis,dfs,ans,省赛,tempX,tempY 来源: https://blog.csdn.net/weixin_45964844/article/details/115582910