def permutationN(n):
a=[None]*n
for i in range(n):
a[i]=i+1 sum=1 for j in range(n):
sum*=(j+1) i=0
for k in range(sum):
# If you want to use stack
#a[i:i+2]=swapStack(a[i],a[i+1])
a[i:i+2]=[a[i+1],a[i]]
print(a)
i+=1
if i==(n-1):
i=0

  

[Algorithm] A nonrecursive algorithm for enumerating all permutations of the numbers {1,2,...,n}的更多相关文章

  1. 【Java】-NO.13.Algorithm.1.Java Algorithm.1.001-【Java 常用算法手册 】-

    1.0.0 Summary Tittle:[Java]-NO.13.Algorithm.1.Java Algorithm.1.001-[Java 常用算法手册 ]- Style:Java Series ...

  2. Prim's Algorithm & Kruskal's algorithm

    1. Problem These two algorithm are all used to find a minimum spanning tree for a weighted undirecte ...

  3. Method for finding shortest path to destination in traffic network using Dijkstra algorithm or Floyd-warshall algorithm

    A method is presented for finding a shortest path from a starting place to a destination place in a ...

  4. [Algorithm] Radix Sort Algorithm

    For example we have the array like this: [, , , , , ] First step is using Counting sort for last dig ...

  5. [Algorithm] A* Search Algorithm Basic

    A* is a best-first search, meaning that it solves problems by searching amoung all possible paths to ...

  6. [Algorithm] Deferred Acceptance Algorithm

    约会配对问题 一.立即接受算法: 对于约会的配对,大家都去追自己最心仪的女生.而这个女生面对几位追求者,要立刻做个决定. 被拒绝的男生们调整一下心情,再去追求心中的 No. 2.以此类推. 这样做法有 ...

  7. [Algorithm] Median Maintenance algorithm implementation using TypeScript / JavaScript

    The median maintenance problem is a common programming challenge presented in software engineering j ...

  8. Algorithm: Euclid's algorithm of finding GCD

    寻找最大公约数方法 代码如下: int gcd (int a, int b) { return b ? gcd (b, a % b) : a; } 应用:求最小公倍数 代码如下: int lcm (i ...

  9. C++ <Algorithm>小小总结

    <algorithm>是C++标准程序库中的一个头文件,定义了C++ STL标准中的基础性的算法(均为函数模板).<algorithm>定义了设计用于元素范围的函数集合.任何对 ...

随机推荐

  1. lua_VC6环境

    1. 下载得到 lua-5.1.4.tar.gz,解压得到 文件夹"lua-5.1.4" 2. 视频[02:00] 将 lua-5.1.4/etc/luavs.bat 复制到 lu ...

  2. 【Golang】解决Go test执行单个测试文件提示未定义问题

    背景 很多人记录过怎么执行Go test单个文件或者单个函数,但是要么对执行单文件用例存在函数或变量引用的场景避而不谈,要么提示调用了其它文件中的模块会报错.其实了解了go test命令的机制之后,这 ...

  3. 使用cocos创建的项目,如何进行源码调试?

    环境cocos3.10,里面包含了cocos2dx 3.10引擎.但是用cocos创建出来的项目,使用的lib和dll是文件夹Cocos\Cocos2d-x\cocos2d-x-3.10\prebui ...

  4. Java中classpath配置

    Java中classpath配置 一.DOS常用命令 二.DOS常用命令实例 2.1 转换目录 cd 1.6* 2.2 删除文件 del 删除文件(windows删除从里往外删) del *.txt ...

  5. pv、uv、ip、tps、qps 等术语简单释义

    跟网站打交道,经常可以听到数据分析之类的专有名词,如pv多少.ip多少.tps多少之类的问题.下面就这些常见的数据给出英文全称及其释义. PV 即 page view,页面浏览量,用户每一次对网站中的 ...

  6. Linux 设置程序开机自启动 (命令systemctl 和 chkconfig用法区别比较)

    之前在Linux centos 7 上安装了apache 和mysql,当时并没有设置开机自动启动. 最近又重新练习网页,每次开机总是要手动启动httpd和mysqld,不方便,就想设置成开机自动启动 ...

  7. 20170719xlVBASmartIndent

    Public Sub SmartIndenterProcedure() Dim OneComp As VBComponent Dim StartLine As Long, EndLine As Lon ...

  8. django-rest-framework登陆认证

    # -*- coding: utf-8 -*- __author__ = 'YongCong Wu' # @Time : 2018/10/23 15:05 # @Email : : 192287802 ...

  9. OAF 清空指定控件或区域的值

    CO if (pageContext.getParameter("ClearBtn") != null) { clearRegion(pageContext, webBean, & ...

  10. SpringMVC实现RESTful服务

    SpringMVC实现RESTful服务 这里只说service,controller层的代码.Mapper层则直接继承Mapper<T>则可以,记住mybatis-config.xml一 ...