next_permutation
来源:互联网 发布:域名劫持查询 编辑:程序博客网 时间:2024/05/20 01:13
参考代码
#include<cstdio>#include<algorithm>using namespace std;int main(){int n,p[10];scanf("%d",&n);for(int i=0;i<n;i++)scanf("%d",&p[i]);sort(p,p+n);//排序,得到p的最小排列 do{for(int i=0;i<n;i++)printf("%d ",p[i]);//输出排列p printf("\n");}while(next_permutation(p,p+n));//求下一个排列 return 0;}
示例输入1
43 4 2 1
示例输出1
1 2 3 41 2 4 31 3 2 41 3 4 21 4 2 31 4 3 22 1 3 42 1 4 32 3 1 42 3 4 12 4 1 32 4 3 13 1 2 43 1 4 23 2 1 43 2 4 13 4 1 23 4 2 14 1 2 34 1 3 24 2 1 34 2 3 14 3 1 24 3 2 1
示例输入2
43 1 1 2
示例输出2
1 1 2 31 1 3 21 2 1 31 2 3 11 3 1 21 3 2 12 1 1 32 1 3 12 3 1 13 1 1 23 1 2 13 2 1 1
阅读全文
0 0
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- next_permutation
- u-boot学习笔记-1、目录结构
- 【数据结构和算法】Day 5
- 小程序无法解析后台的json
- ORA-12547: TNS:lost contact+oracle 开启监听失败
- 使用mvn插件surefire 执行工程单元测试 出现OOM的解决分析
- next_permutation
- 查找算法总结
- Python标准数据类型
- 中国剩余定理
- 接口实现类方法的回调
- Vue2+VueRouter2+Webpack+Axios 构建项目实战2017重制版(四)调整 App.vue 和 router 路由
- char *s 和 char s[] 的区别
- 堆排序算法分析与实现
- python的numpy包中shape,tile,argsort函数与sorted函数使用方法