首页 > 其他 > 详细

乱七八糟代码合集?(?>?<?)?

时间:2019-07-02 21:18:50      阅读:271      评论:0      收藏:0      [点我收藏+]

1.全排列

技术分享图片
#include<bits/stdc++.h>
using namespace std;
int n = 3;
bool hashtable[100] = {false};
int P[100] = {-1};
int count_num = 0;
void f(int index){
    if(index == n + 1){
        for (int i = 1; i <= n; i++){
            printf("%d ", P[i]);
        }
        count_num++;
        printf("\n");
        return;
    }
    for (int x = 1; x <= n; x++){
        if (hashtable[x] == false){
            P[index] = x;
            hashtable[x] = true;
            f(index + 1);
            hashtable[x] = false;
        }
    }
}

int main(){
    f(1);

    printf("\ncount=%d", count_num);
    return 0;
}
输出全排列

2.八皇后

 

 

 

(未完待续~)

 

乱七八糟代码合集?(?>?<?)?

原文:https://www.cnblogs.com/yellowzunzhi/p/11123045.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!