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. java编写编译器和解释器

     on 2012-07-14 21:24 Bang 阅读(102) 评论(0) 编辑 收藏  续 第二部分 初始后端实现 框架后端支持编译器和解释器.现在框架抽象类Backend有两个极简版实现,一个 ...

  2. Idea设置默认不折叠一行的函数

  3. spring事务管理方式大全

    http://blog.csdn.net/baibinboss/article/details/64922472

  4. 一个简单可参考的API网关架构设计

    网关一词较早出现在网络设备里面,比如两个相互独立的局域网段之间通过路由器或者桥接设备进行通信, 这中间的路由或者桥接设备我们称之为网关. 相应的 API 网关将各系统对外暴露的服务聚合起来,所有要调用 ...

  5. 20170814xlVBA PowerPoint分类插图加说明

    Public Sub AddPictures() Dim ppApp As PowerPoint.Application Set ppApp = New PowerPoint.Application ...

  6. 12月7日,几个错误,拼写错误,遗漏符号:,记忆有误,max-width的作用。gem mini_magick, simple_form

    ❌: 1. /Users/chentianwei/jdstore3/jdstore/config/routes.rb:6:in `block in <top (required)>': u ...

  7. Tree Cutting (Hard Version) CodeForces - 1118F2 (树形DP,计数)

    大意:给定树, 每个点有颜色, 一个合法的边集要满足删除这些边后, 每个连通块内颜色仅有一种, 求所有合法边集的个数 $f[x][0/1]$表示子树$x$中是否还有与$x$连通的颜色 对于每种颜色已经 ...

  8. MVC5 学习笔记 controller

    主要参考书籍<ASP.NET MVC5 高级编程(第5版) > 作者:Jon Galloway等 1. MVC 表示 模型-视图-控制器.MVC是一种用于开发应用程序的模式,具备良好的架构 ...

  9. iOS UI-常用控件

    #import "ViewController.h" @interface ViewController ()<UITextFieldDelegate> // 标题标签 ...

  10. PHP:第一章——php中的输出函数

    <?php //PHP中的输出函数 //echo()函数输出一个或多个字符串: echo 'PHP中的echo<br/>'; //var_dump()此函数显示关于一个或多个表达式的 ...