2613 - 全排列问题
时间限制 : 1 秒
内存限制 : 128 MB
输出自然数1到n所有不重复的排列,即n的全排列,要求所产生的任一数字序列中不允许出现重复的数字。
题目输入
n(1≤n≤9)
题目输出
由1~n组成的所有不重复的数字序列,每行一个序列。
输入/输出样例
输入格式
3
输出格式
1 2 3 1 3 2 2 1 3 2 3 1 3 1 2 3 2 1
Python解答
# coding=utf-8 import itertools def soluction(nums): templt = itertools.permutations(nums) reslt = [] for i in templt: reslt.append(i) return reslt n = int(input()) nums = [i for i in range(1, n + 1)] for i in soluction(nums): for j in i: print('%5d' % j, end='') print()