codevs 全排列 1294
来源:互联网 发布:网络电影制作合同 编辑:程序博客网 时间:2024/05/17 09:19
题目描述 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
给出一个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
a:array[1..10]of longint;
b:array[1..10]of boolean;
n,i:longint;
procedure dfs(t:longint);
var
i:longint;
begin
if t>n then
begin
for i:=1 to n do
write(a[i],' ');
writeln;
exit;
end;
for i:=1 to n do
if b[i] then
begin
b[i]:=false;
a[t]:=i;
dfs(t+1);
b[i]:=true;
end;
end;
begin
fillchar(b,sizeof(b),true);
readln(n);
dfs(1);
end.
0 0
- 【codevs 1294】全排列
- CODEVS 1294全排列
- codevs 全排列 1294
- codevs 1294 全排列
- 【codevs黄金】1294 全排列
- DFS练习-codevs-1294全排列
- 全排列 (codevs 1294)题解
- Codevs 1294 全排列(DFS)
- Codevs P1294 全排列
- codevs天梯全排列 普通dfs
- wikioi 1294 全排列
- wiki 【1294 全排列 】
- 【Wikioi】1294全排列
- wikioi 1294 全排列
- 1294 全排列
- 1294 全排列
- Codevs 1013 求先序排列
- 【codevs 1013】求先序排列
- JDBC使用Dao工厂模式读取properties配置文件实现解耦
- 多个 ng-app 中 Controllers & Services 之间的通信
- 开发板系统安装准备
- PHP学习笔记——错误处理
- Scrum Master与Project Manager的区别
- codevs 全排列 1294
- Permutations II
- Mysql自动设置时间(自动获取时间,填充时间)
- 抓取 题目描述 生成 解题报告 模板 python
- 洛谷 P1282 多米诺骨牌
- 大大维的游戏机计划2--一个自制的类似2048的小游戏
- cvCreateVideoWriter生成AVI视频时返回为空问题的终极解决方案
- CSS选择器兼容情况
- hihoCoder - 1270 建造基地