zoukankan      html  css  js  c++  java
  • n个数的全排列

    #define _CRT_SECURE_NO_DEPRECATE
    #include<iostream>
    #include<string>
    #include<algorithm>
    #define MAX 1100
    using namespace std;
    
    int perm1[MAX], perm2[MAX];
    bool used[MAX];
    void _permutation(int pos, int n){
        if (pos == n){
            for (int i = 0; i < n; i++)
                cout << perm2[i] << ",";
            cout << endl;
            return;
        }
        for (int i = 0; i < n; i++){
            if (!used[i]){
                perm2[pos] = perm1[i];
                used[i] = 1;
                _permutation(pos + 1, n);
                used[i] = 0;
            }
        }
    }
    int main()
    {
        int n = 4;
        for (int i = 0; i < n; i++)
            perm1[i] = i;
        memset(used, 0, sizeof(used));
        _permutation(0, n);
        system("pause");
        return 0;
    }
    世上无难事,只要肯登攀。
  • 相关阅读:
    IO库 8.5
    IO库 8.4
    标准模板库——IO库
    IO库 8.3
    IO库 8.2
    IO库 8.1
    CF 599D Spongebob and Squares(数学)
    Django入门学习(一)
    hdu 5733
    uva 11210
  • 原文地址:https://www.cnblogs.com/littlehoom/p/3550799.html
Copyright © 2011-2022 走看看