【NEEPU OJ】1024--Full Permutation
2019-03-05 12:15
295 查看
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34072526/article/details/88176003
Description
给出一个n, 请输出n的所有全排列
Input
读入仅一个整数n (1<=n<=10)
Output
一共n!行,每行n个用空格隔开的数,表示n的一个全排列。并且按全排列的字典序输出。
输入样例 1
3
输出样例 1
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
提示
从n个不同元素中任取m(m≤n)个元素,按照一定的顺序排列起来,叫做从n个不同元素中取出m个元素的一个排列。当m=n时所有的排列情况叫全排列。
公式:全排列数f(n)=n!(定义0!=1),如1,2,3三个元素的全排列为:
1,2,3
1,3,2
2,1,3
2,3,1
3,1,2
3,2,1
共3*2*1=6种。
来源
Own
代码
#include <iostream> #include <algorithm> using namespace std; int main(){ int n, i; int a[10] = {0}; cin >> n; for(i = 0; i < n; i++) a[i] = i + 1; do{ for(i = 0; i < n - 1; i++) cout << a[i] << " "; cout << a[n - 1] << endl; }while(next_permutation(a, a + n)); return 0; }
相关文章推荐
- 【NEEPU OJ】1005--This is a easy problem 4 U.
- 【NEEPU OJ】1004--Double Eleven
- 【NEEPU OJ】3004--马走日
- 【NEEPU OJ】1012--Where is the gold?
- NIT-OJ-1024-全文检索-解题报告
- LeetCode OJ Next Permutation
- 九度OJ 1024 畅通工程
- 九度oj 题目1024:畅通工程 【ZJU2007考研机试题5】
- LeetCode OJ Permutation Sequence
- oj 1031 random permutation
- buaaoj230——next_permutation的应用
- 【九度OJ】1024【并查集】【BST】【畅通工程系列2007】
- LeetCode OJ Permutation Sequence
- 【ny-oj】-366-D的小L(STL-全排列(next_permutation()))
- 九度oj 1024 (杭电)畅通工程
- 九度OJ 1024:畅通工程
- full permutation
- 杭电OJ——1024 Max Sum Plus Plus
- 【九度OJ】题目1024:畅通工程 解题报告
- OJ_1024 畅通工程