python不带重复的全排列代码
(编辑:jimmy 日期: 2024/11/17 浏览:3 次 )
复制代码 代码如下:
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)
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],
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)
下一篇:python在多玩图片上下载妹子图的实现代码