题目描述 Description

给出一个n, 请输出n的所有全排列

输入描述 Input Description

读入仅一个整数n   (1<=n<=10)

输出描述 Output Description

一共n!行,每行n个用空格隔开的数,表示n的一个全排列。并且按全排列的字典序输出。

样例输入 Sample Input

3

样例输出 Sample Output

1 2 3

1 3 2

2 1 3

2 3 1

3 1 2

3 2 1

var n:longint;
a:array[..]of longint;
p:array[..] of boolean;
procedure print;
var i:longint;
begin
for i:= to n do write(a[i],' ' );
writeln;
end;
procedure try(k:longint);
var i:longint;
begin
if k=n+ then print
else
for i:= to n do
if p[i] then
begin
a[k]:=i;
p[i]:=false;
try(k+);
p[i]:=true;
end;
end;
begin
read(n);
fillchar(p,sizeof(p),true);
fillchar(a,sizeof(a),);
try();
end.

[CODEVS1294]全排列的更多相关文章

  1. PHP实现全排列(递归算法)

    算法描述:如果用P表示n个元素的全排列,而Pi表示n个元素中不包含元素i的全排列,(i)Pi表示在排列Pi前面加上前缀i的排列,那么n个元素的全排列可递归定义为:    ① 如果n=1,则排列P只有一 ...

  2. hdu5651 xiaoxin juju needs help (多重集的全排列+逆元)

    xiaoxin juju needs help 题意:给你一个字符串,求打乱字符后,有多少种回文串.                      (题于文末) 知识点: n个元素,其中a1,a2,··· ...

  3. [LeetCode] Palindrome Permutation II 回文全排列之二

    Given a string s, return all the palindromic permutations (without duplicates) of it. Return an empt ...

  4. [LeetCode] Palindrome Permutation 回文全排列

    Given a string, determine if a permutation of the string could form a palindrome. For example," ...

  5. [LeetCode] Permutations II 全排列之二

    Given a collection of numbers that might contain duplicates, return all possible unique permutations ...

  6. [LeetCode] Permutations 全排列

    Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...

  7. 全排列算法的JS实现

    问题描述:给定一个字符串,输出该字符串所有排列的可能.如输入“abc”,输出“abc,acb,bca,bac,cab,cba”. 虽然原理很简单,然而我还是折腾了好一会才实现这个算法……这里主要记录的 ...

  8. java实现全排列

    前天上午的面试遇到了一个用java实现一串数字的全排列的题,想来想去用递归最方便,可是没有在规定的时间内完成555,今天上午有空便继续写,以下是完成后的代码: import java.util.Arr ...

  9. poj3187-Backward Digit Sums(枚举全排列)

    一,题意: 输入n,sum,求1~n的数,如何排列之后,相邻两列相加,直到得出最后的结果等于sum,输出1~n的排列(杨辉三角)  3 1 2 4 //1~n 全排列中的一个排列  4 3 6  7 ...

随机推荐

  1. leetcode169——Majority Element (C++)

    Given an array of size n, find the majority element. The majority element is the element that appear ...

  2. 【CF493E】【数学】Vasya and Polynomial

    Vasya is studying in the last class of school and soon he will take exams. He decided to study polyn ...

  3. 字符串匹配算法——KMP、BM、Sunday

    KMP算法 KMP算法主要包括两个过程,一个是针对子串生成相应的“索引表”,用来保存部分匹配值,第二个步骤是子串匹配. 部分匹配值是指字符串的“前缀”和“后缀”的最长的共有元素的长度.以“ABCDAB ...

  4. CentOS6.5下docker的安装及遇到的问题和简单使用

    Docker是一个开源的应用容器引擎,可以轻松的为任何应用创建一个轻量级的.可移植的.自给自足的容器.利用Linux的LXC.AUFS.Go语言.cgroup实现了资源的独立,可以很轻松的实现文件.资 ...

  5. getopt getopt_long

    getopt_long支持长选项的命令行解析,使用man getopt_long,得到其声明如下: #include <getopt.h> int getopt_long(int argc ...

  6. Java Servlet 接收上传文件

    在Java中使用 Servlet 来接收用户上传的文件,需要用到两个apache包,分别是 commons-fileupload 和 commons-io 包: 如果直接在doPost中,使用requ ...

  7. 用eclipse建立简单WebService客户端,使用WSDL,用于短信接口发送

    使用工具:eclipse 标准版,不用任何插件. 操作步骤: 建立java Project 命名为mess: 再在project上右键,选择other,选择web service文件类别,选择web ...

  8. workerman安装

    1.workerman安装 workerman是php的一个socket框架,简化了socket编程,已经为很多企业所用,今天在centos的ngix+php下安装了workerman,过程记录如下. ...

  9. Android Context创建过程

        特定的资源或者类构成了Android应用程序的运行上下文环境 PackageManager, ClassLoader, Assert等等 Android应用程序窗口的运行上下文环境是通过Con ...

  10. Python学习笔记——几种数据类型

    1. 列表list: Python内置的一种数据类型是列表:list,用中括号[]表示.list是一种有序的集合,可以随时添加和删除其中的元素,而且元素的类型不必相同.list可以通过下标来访问,范围 ...