1. include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. void swap(char &c1, char &c2){
  7. char tmp = c1;
  8. c1= c2;
  9. c2= tmp;
  10. }
  11.  
  12. void perm(string s, int i, int n){
  13.  
  14. if(i== n){
  15. cout << s << endl;
  16. }
  17.  
  18. for(int j=i;j<=n;j++){
  19. swap(s[i], s[j]);
  20. perm(s, i+, n);
  21. swap(s[i], s[j]);
  22. }
  23.  
  24. }
  25.  
  26. int main(){
  27.  
  28. string p= "";
  29. perm(p, , );
  30.  
  31. }

permutation求全排列的更多相关文章

  1. 求全排列Permutation

    是在教材(<计算机算法设计与分析(第4版)>王晓东 编著)上看见的关于求全排列的算法: 我们可以看一下书上怎么写的: #include<bits/stdc++.h> using ...

  2. PermutationsUnique,求全排列,去重

    问题描述:给定一个数组,数组里面有重复元素,求全排列. 算法分析:和上一道题一样,只不过要去重. import java.util.ArrayList; import java.util.HashSe ...

  3. 60. Permutation Sequence(求全排列的第k个排列)

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

  4. [LeetCode]60. Permutation Sequence求全排列第k个

    /* n个数有n!个排列,第k个排列,是以第(k-1)/(n-1)!个数开头的集合中第(k-1)%(n-1)!个数 */ public String getPermutation(int n, int ...

  5. lintcode :Permutation Index 排列序号

    题目: 排列序号 给出一个不含重复数字的排列,求这些数字的所有排列按字典序排序后该排列的编号.其中,编号从1开始. 样例 例如,排列[1,2,4]是第1个排列. 解题: 这个题目感觉很坑的.感觉这只有 ...

  6. 【LeetCode每天一题】Permutation Sequence(排列序列)

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

  7. 【康拓展开】及其在求全排列第k个数中的应用

    题目:给出n个互不相同的字符, 并给定它们的相对大小顺序,这样n个字符的所有排列也会有一个顺序. 现在任给一个排列,求出在它后面的第i个排列.这是一个典型的康拓展开应用,首先我们先阐述一下什么是康拓展 ...

  8. LeetCode:Permutations, Permutations II(求全排列)

    Permutations Given a collection of numbers, return all possible permutations. For example, [1,2,3] h ...

  9. next_permutation()函数 和 prev_permutation() 按字典序求全排列

    next_permutation功能:    求一个排序的下一个排列的函数,可以遍历全排列,要包含头文件<algorithm> 与之完全相反的函数还有prev_permutation 这个 ...

随机推荐

  1. php 编程效率(2)

    1.尽量静态化: 如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍. 当然了,这个测试方法需要在十万级以上次执行,效果才明显. 其实静态方法和非静态方法的 ...

  2. [Rails] 从 Request 到 Response(1)

    本文翻译自:Rails from Request to Response 系列:个人选择了自己感兴趣的部分进行翻译,需要阅读原文的同学请戳前面的链接. 第一部分 导言(Introduction) 服务 ...

  3. fopen()函数以"a+"方式打开一个不存在的文件后读写出现问题

    问题:在完成课后习题的时候,使用fopen()函数以"a+"方式打开一个不存在的文件时,写入.读取出现错误: //添加用户输入单词后,在单词头加入编号,确保编号跟着前面的开始排序 ...

  4. Latex问题收集

    1. Latex中的空格 两个quad空格 a \qquad b 两个m的宽度 quad空格 a \quad b 一个m的宽度 大空格 a\ b 1/3m宽度 中等空格 a\;b 2/7m宽度 小空格 ...

  5. 区块链Readme.md

    #Welcome to Azure Blockchain Projects This Repo host Azure related blockchain and distributed ledger ...

  6. php 导出 Excel 报错 exception 'PHPExcel_Calculation_Exception' with message

    exception 'PHPExcel_Calculation_Exception' with message '粉丝数据!C2679 -> Formula Error: Operator '= ...

  7. digitalocean最新优惠码赠送10美元

    digitalocean是我非常喜欢的vps服务商,目前手头还有十来个digitalocean vps服务器.用了三年多digitalocean后,我发现digitalocean一点小技巧.比如,如果 ...

  8. python 信用卡系统+购物商城见解

    通过完成信用卡系统+购物商城 使自己在利用 字典和列表方面有了较大的提升,感悟很深, 下面将我对此次作业所展示的重点列表如下: #!/usr/bin/env python3.5 # -*-coding ...

  9. TFS 2012使用简介

    为什么使用TFS 2012进行源代码管理——TFS 2012使用简介(一)  来源:雪雁 http://www.cnblogs.com/codelove/archive/2013/03/16/2963 ...

  10. 手动编译生成apk

    转载一篇介绍如何去手动编译生成apk的文章: http://jojol-zhou.iteye.com/blog/729254