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. signal_windows

    1.Qt532(vs2010 opengl) // ZC: windows signal: // http://blog.csdn.net/mergerly/article/details/79521 ...

  2. [STL][C++]VECTOR

    参考:http://blog.csdn.net/hancunai0017/article/details/7032383 vector(向量): C++中的一种数据结构,确切的说是一个类.它相当于一个 ...

  3. TTFB

    TTFB    Time To First Byte 1.含义 最初的网络请求被发起”到“从服务器接收到第一个字节前”所花费的毫秒数 包含了 TCP连接时间,发送HTTP请求时间和获得响应消息第一个字 ...

  4. infra 仪表盘效果

    private void Gauge2() { // Infragistics.WebUI.UltraWebGauge.UltraGauge ultraGauge2 = //new Infragist ...

  5. 20170728xlVba简单的匹配

    Sub MatchData() Dim i As Long, EndRow As Long, Key As String Dim Rng As Range Dim Dic As Object Set ...

  6. UVA-10497 Sweet Child Makes Trouble (计数+高精度)

    题目大意:这是一道简单排列组合题 .简单说下题意:n件物品,把这n件物品放到不是原来的位置,问所有的方案数.所有的位置都没有变. 题目解析:按照高中的方法,很快得到一个递推公式:f [n]= (n-1 ...

  7. 访问IIS元数据库失败的解决方法

    这两天在调试一个Asp.net程序时,出现了“访问IIS元数据库失败”的错误信息,最后终于摸索出了解决问题的方法.公布如下: 1.依次点击“开始”-“运行”. 2.在“运行”栏内输入 “C:\WIND ...

  8. sql连接详解

    笛卡尔乘积: A={a, b},集合B={0, 1, 2},则AxB的笛卡尔积为{(a, 0), (a, 1), (a, 2), (b, 0), (b, 1), (b, 2)}; (AxB≠BxA) ...

  9. JavaScript 对象的使用

    JavaScript支持面向对象的编程方法. 2.9.1 window对象(窗口对象)的常用方法 内部函数 alert ( ) ,实际上是 window 对象的方法,写成全称为 window . al ...

  10. EBS 快速创建供应商的标准创建逻辑

    该页面经过了客户化,只保留了这三个字段. 点击应用时执行 oracle.apps.pos.supplier.webui.SuppCrtCO String s29 = (String)((OAAppli ...