欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python不带重复的全排列代码

程序员文章站 2022-06-18 08:34:35
复制代码 代码如下:from sys import argvscript, start, end = argvvis = [0, 0, 0, 0, 0, 0, 0, 0,...
复制代码 代码如下:

from sys import argv
script, start, end = argv
vis = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
ans = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
def dfs(cur, m):
 ans[cur] = m
 if cur == int(end) - int(start) + 1:
  for i in xrange(int(start), int(end) + 1):
   print ans[i],
  print
  return
 cur = cur + 1
 for i in xrange(int(start), int(end) + 1):
  if vis[i] == false:
   vis[i] = true
   dfs(cur, i)
   vis[i] = false

for i in xrange(1, len(vis)):
 vis[i] = false
dfs(0, start)