国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

全排列

2019-11-06 06:08:17
字體:
來源:轉載
供稿:網友

全排列類似與N皇后那個問題

1.用遞歸寫

#include <iostream>#include <algorithm>#include <cstring>#include <string>using namespace std;const int M = 8;char str[M];char permutation[M];bool used[M] = {0};int L = 0;void Permutation(int n){ if( n == L ) { permutation[L] = 0; cout << permutation << endl; return ; } for(int i = 0;i < L; ++i) { if( !used[i]) { used[i] = true; permutation[n] = str[i]; Permutation(n+1); used[i] = false; } }}int main(){ cin >> str; L = strlen(str); sort(str,str+L); Permutation(0); return 0;}

2.使用STL的next_permutation庫寫

#include<iostream>#include<algorithm>#include<cstring>using namespace std;char a[10];int main(){ cin>>a; int h=strlen(a); sort(a,a+h); do { cout<<a<<endl; }while(next_permutation(a,a+h));//STL模板}
上一篇:C# 線程

下一篇:urlparse相關知識

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 刚察县| 察雅县| 义乌市| 西乌珠穆沁旗| 阳泉市| 霍州市| 尚志市| 鸡泽县| 资阳市| 江油市| 广宗县| 泾阳县| 沙河市| 平舆县| 万载县| 平邑县| 扬中市| 宁阳县| 高密市| 嵊州市| 张掖市| 沙河市| 偃师市| 墨竹工卡县| 十堰市| 瓮安县| 青浦区| 临高县| 呼玛县| 张家界市| 阜新| 高邑县| 和平区| 综艺| 香港 | 葵青区| 瓮安县| 教育| 谷城县| 河曲县| 锦屏县|