C++:数组排列组合的问题。
来源:互联网 发布:电商运营数据分析 视频 编辑:程序博客网 时间:2024/06/06 01:11
//求一个长度为n的数组中长度为m的所有排列组合。#include <iostream>#include <stack>using namespace std;stack<int> st;void Grial(int a[], int m,int n, int length){ if (st.size() == 3) { stack<int> temp = st; while (temp.empty() == false) { cout << temp.top() << " "; temp.pop(); } cout << endl; return; } else { for (int i = m; i < n; i++) { st.push(a[i]); Grial(a, i+1,n, length); st.pop(); } }}int main(){ int a[] = {1,2,3,4,5,6,7}; Grial(a,0, sizeof(a) / sizeof(int), 3);}*///求一个数组的全排列,代码情况如下:#include <iostream>using namespace std;void Grial(int a[], int n,int m){ if (n == m) { for (int i = 0; i < m; i++) { cout << a[i] << " "; } cout << endl; } else { for (int i = n; i < m; i++) { std::swap(a[i],a[n]); Grial(a,n+1,m); std::swap(a[i],a[n]); } }}int main(){ int a[] = { 1, 2, 3, 4 }; Grial(a, 0,sizeof(a) / sizeof(int)); return 0;}
0 0
- C++:数组排列组合的问题。
- C++数组的排列组合
- c/c++算法 排列组合问题
- 一个排列组合的问题
- 字符串的排列组合问题
- 字符串的排列组合问题
- 字符串的排列组合问题
- 字符串的排列组合问题
- 小球的排列组合问题
- 字符串的排列组合问题
- 字符串的排列组合问题
- 字符串的排列组合问题
- 字符串的排列组合问题
- 字符串的排列组合问题
- 常见的排列组合问题
- 关于数组元素的排列组合
- C语言如何打印一个数组排列组合?
- 求二维数组的全排列组合,二位数组的自乘积问题
- 算法导论 使用单链表实现队列
- Android学习——Activity
- H264码流结构分析
- 学习资料(3)-Github相关
- unity实现鼠标点击位置小脚印标志
- C++:数组排列组合的问题。
- 151 Reverse Words in a String
- C Prime Plus第十三章
- 新手解决winform问题的一点小经验
- 使用IOS7原生API进行二维码条形码的扫描
- idg笔试--e代驾笔试--完美笔试--美团面试回忆总结
- 项目实战No9 不等高cell高度 相册图片
- 结构型模式:适配器模式
- PUNCH算法