(藍橋杯)第八屆A組C/C++方格分割

#include<iostream>  
#include<memory.h>
#include<stack>
#include<string>
#include<cmath>
#include<map>
#include<algorithm> 
#include<sstream>
#include<set>
#include<queue>
using namespace std;
int N=6;
int sum=0;
int visited[7][7];
void dfs(int row,int colum)
{
    if(visited[row][colum]==1)
        return;
    if(row==0||row==N||colum==0||colum==N)
    {
        sum++;
        visited[row][colum]=0;
        return;
    }
    
    visited[row][colum]=1;
    visited[N-row][N-colum]=1;
        
    dfs(row+1,colum);
    dfs(row-1,colum);
    dfs(row,colum+1);
    dfs(row,colum-1);
    
    visited[row][colum]=0;
    visited[N-row][N-colum]=0;
}
int main()
{
    
    memset(visited,0,sizeof(visited));
    dfs(3,3);
    cout<<sum/4;
     
}
相關文章
相關標籤/搜索