首页 > 编程 > Python > 正文

python不带重复的全排列代码

2019-11-25 18:38:59
字体:
来源:转载
供稿:网友
复制代码 代码如下:

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) 
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表