题目描述 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. JVM - 内存溢出问题排查相关命令jcmd jmap

    jcmd http://docs.oracle.com/javase/8/docs/technotes/tools/windows/jcmd.html jcmd-l  列出正在执行的JAVA进程ID ...

  2. 《C语言学习笔记》指针数组及其应用

    C语言中,最灵活但又容易出错的莫过于指针了.而指针数组,是在C中很常见的一个应用.指针数组的意思是说,这个数组存储的所有对象都为指针.除了存储对象为指针,即一个地址外,其它操作和普通数组完全一样. # ...

  3. php 验证码生成方法 及使用

    基本思路是: 在生成图片的页面中(as: yzm.php)1.设置生成的图片的宽度和高度:2.设置图片要写入的字符:3.截取显示在图片上的字符;4.开启session,把上面截取的字符存放在sessi ...

  4. javascript 写策略模式,商场收银打折优惠策略

    [Decode error - output not utf-8] ----------------------------- 购物清单 方便面 : 100 x 50 = 5000 | 4000 菊花 ...

  5. linux下 链接 sqlserver数据库 驱动的安装

    1.必需安装freetds 安装pdo_dblib扩展首先需要安装freetds. freeTDS的最新稳定版是0.91,这个可以在官网上下载http://www.freetds.org/ ,也可以在 ...

  6. (转载)在状态栏即时显示Hint

    在状态栏即时显示Hint(所有窗口,包括子窗口控件的hint) 在主窗体中放入一个ApplicationEvents控件.添加如下代码.其中Items[***]中的***代表状态栏的各个子panel, ...

  7. Python 学习之urllib模块---用于发送网络请求,获取数据(4)

    承接将查询城市编码的结果保存到文件中,以字典的形式保存,目的是为了在查询某个城市的天气的时候,能够通过输入的城市名称,找到对应的城市编码.所以此结果字典的数据结构,就是city={城市名称:城市编码} ...

  8. Django生产环境的部署-Apache-mod_wsgi

    httpd.conf配置 ServerSignature On ServerTokens Full Define APACHE24 Apache2.4 Define SERVER_BASE_DIR & ...

  9. windows server 2008 R2 忘记administrator密码

    第一步: 插入安装光盘,重光驱启动系统,在选择“安装语言”的地方,按shift+F10 在弹出的CMD窗口中,输入以下地址: x:\>c: c:\>cd windows\system32 ...

  10. C# 在SQLite数据库中存储图像 z

    C# 在SQLite数据库中存储图像 更多 0 C# SQLite   建表语句 CREATE TABLE [ImageStore]([ImageStore_Id] INTEGER NOT NULL ...