Full Permutation


全排列问题, 将1~n这n个整数按字典序排放

  • 划分:

    • 输出1开头的全排列
    • 输出2开头的全排列
    • ......
    • 输出n开头的全排列
  • 递归边界:当下标1 ~ n 位都已经填好了,此时表示排列已经生成,可以输出。

  • 递归子式:即上述划分

//以3为例的全排列
#include <cstdio> const int maxn = 11;
int n, p[maxn], hashTable[maxn] = {false};
//p为当前排列,hashTable记录x是否在p中
void generateP(int index) {
if (index == n + 1) { //递归边界
for (int i = 1; i <= n; i++) {
printf("%d", p[i]);
}
printf("\n");
return;
}
for (int x = 1; x <= n; x++) {
if (hashTable[x] == false) {
p[index] = x;
hashTable[x] = true; //记录x已在p中
generateP(index + 1); //处理下一位
hashTable[x] = false; //已处理完p[index]为x的子问题,还原状态
}
}
} int main() {
n = 3;
generateP(1);
return 0;
}

Full permutation的更多相关文章

  1. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  2. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  3. [LeetCode] Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. For example," ...

  4. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Next Permutation 下一个排列

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  6. Leetcode 60. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  7. UVA11525 Permutation[康托展开 树状数组求第k小值]

    UVA - 11525 Permutation 题意:输出1~n的所有排列,字典序大小第∑k1Si∗(K−i)!个 学了好多知识 1.康托展开 X=a[n]*(n-1)!+a[n-1]*(n-2)!+ ...

  8. Permutation test: p, CI, CI of P 置换检验相关统计量的计算

    For research purpose, I've read a lot materials on permutation test issue. Here is a summary. Should ...

  9. Permutation

    (M) Permutations (M) Permutations II (M) Permutation Sequence (M) Palindrome Permutation II

  10. Next Permutation

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

随机推荐

  1. rocketmq源码打包步骤

    1,从git上面克隆好源码之后,进入rocketmq目录,执行: mvn -Prelease-all -DskipTests clean install 2,打包完成之后,进入distribution ...

  2. 0007-20180403-python-自动化基础学习000--while-if 循环实操

    python-自动化基础学习000 Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64 ...

  3. dubbo框架整合常见问题

    逆向工程常见问题总结 tomcat7插件启动项目卡在:log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for ...

  4. eclipse无法断点调试JDK源码的问题

    最近换了新版的eclipse,在jdk源码里面,打断点发现无法进入源码调试,程序直接跳过,已查资料发现自己eclipse配置的是jre环境的. 此处要配成jdk目录才有效 打开preferences, ...

  5. 各版本最新的Visual C++可再发行组件包(Redistributable Package)下载和合集

    Microsoft Visual C++ 2005 Redistributable Package (x86):Microsoft Visual C++ 2005 可再发行组件包 (x86):http ...

  6. iperf使用指南

    注意:iperf板上版本和PC上版本要一致,至少都要是2或者3,不能一个是2,一个是3. You also get a "connection refused" error whe ...

  7. vc++2010如何新建项目并在控制台打印helloworld

    关于写c++使用什么集成开发环境的问题其实挺纠结的.我找了好久找到codeblocks,发现这款IDE还是最适合用在最标准的c++语法环境中.其实先前装过vs2015旗舰版,但是这款软件太大了,非常消 ...

  8. 【做题】SDOI2017硬币游戏——方程&概念处理

    原文链接 https://www.cnblogs.com/cly-none/p/9825339.html 题意:给出\(n\)个长度为\(m\)的互不相同的01串.有另一个串,初始为空.不断进行如下操 ...

  9. jQuery学习笔记(一)

    jQuery 事件 - ready() 方法 实例 在文档加载后激活函数(): $(document).ready(function(){ $(".btn1").click(fun ...

  10. 去除pt种里tracker的方法

    1.下载BEncode Editor,打开 2.把下载的种子拖进去,可以看到这样的: tracker就是箭头指的地方,这个包含了个人帐号独一无二的私钥,如果泄露给别人的话别人下载就是走的你的帐号,轻则 ...