color


私信TA

用户名:Missa

访问量:2386

签 名:

等  级
排  名 9672
经  验 1079
参赛次数 2
文章发表 3
年  龄 0
在职情况 学生
学  校 qweq
专  业

  自我简介:

TA的其他文章

棋盘多项式
浏览:105

解题思路: 

                (X,Y)不能放的情况?

                        a. (X,Y) 为0  

                        b. 本行和本列之前无洞且已经放有车


注意事项:

参考代码:

#include <iostream>
using namespace std;
const int N = 10;
int graph[N][N];
int vis[N][N];
int ans[N*N];
int n;

bool justify(int x,int y){
    if(graph[x][y]==0||vis[x][y]) return false;
    for(int i = x-1;i>0;i--){
        if(vis[i][y]) return false;
        if(graph[i][y]==0) break;
    }
    for(int i =y-1;i>0;i--){
        if(vis[x][i]) return false;
        if(graph[x][i]==0) break;
    }
    return true;
}

void find_ans(int alrea_che,int x,int y){
    if(alrea_che<=(n-1)*(n-1)){
        ans[alrea_che]++;
    }
    //在(x,y) 之后选位置
    for(int x1 = x;x1<=n;x1++){
        int y1 = x1==x? y:1;
        for(; y1<=n;y1++){
            if(justify(x1,y1)){
                vis[x1][y1] = 1;
                find_ans(alrea_che+1,x1,y1);
                vis[x1][y1] = 0;
            }
        }
    }
}
          
int main()
{
    cin>>n;
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=n;j++){
            int a; cin>>a;
            graph[i][j] = a;
        }
    }
    find_ans(0,1,0);
    for(int i = 1;i<=n*n;i++){
       if(ans[i])  cout<<ans[i]<<endl;
    }
    return 0;
}

  

 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区