8.3—暴力枚举法—Permutations
来源:互联网 发布:linux下的下载工具 编辑:程序博客网 时间:2024/06/07 06:00
描述
Given a collection of numbers, return all possible permutations.
For example, [1,2,3] have the following permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1],
[3,1,2], and [3,2,1].
Given a collection of numbers, return all possible permutations.
For example, [1,2,3] have the following permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1],
[3,1,2], and [3,2,1].
#include<iostream>#include<vector>#include<iomanip>using namespace std;void swap(int &a, int &b){int temp = a;a = b;b = temp;}void Permutations(int a[], int from, int to){if (a == NULL)return;if (from == to){for (int i = 0; i <= to; i++)cout << a[i];cout << endl;}else{for (int i = from; i <= to; i++){swap(a[from], a[i]);Permutations(a, from + 1, to);swap(a[from], a[i]);}}}int main(){const int n = 3;int a[n] = { 1, 2,3 };int from = 0;int to =n-1;Permutations(a, from, to);}
阅读全文
0 0
- 8.3—暴力枚举法—Permutations
- 8.4—暴力枚举法—Permutations II
- leetcode:暴力枚举法之Permutations
- 8.1—暴力枚举法—Subsets
- 8.5—暴力枚举法—Combinations
- 暴力法求解——简单枚举(除法)
- 8.2—暴力枚举法—Subsets II
- hdu——4462(暴力枚举)
- 暴力枚举法总结
- 暴力枚举法总结
- 暴力枚举法专题
- 暴力求解-枚举法
- 暴力枚举法总结
- poj 3080 暴力法 KMP+暴力枚举
- Permutations—回溯法求解
- 8.6—暴力枚举法—Letter Combinations of a Phone Number
- CF——#142div2 C(暴力枚举)
- HDU5610——暴力枚举(可减少遍历次数)
- fragment常用方式总结
- 8.2—暴力枚举法—Subsets II
- 微信小程序实现列表上拉加载,自动适应屏幕
- Kotlin 设计模式-策略
- asd
- 8.3—暴力枚举法—Permutations
- 8.4—暴力枚举法—Permutations II
- DirectX12笔记 初始化
- 系统设计师必备技能与工具有哪些?
- easyui复选框树动态加载后台数据,实现自动选中数据库中数据。后台语言是.NET
- 8.5—暴力枚举法—Combinations
- 建立多线程的两种方法
- select poll 与epoll模型的总结
- 8.6—暴力枚举法—Letter Combinations of a Phone Number