从M个不同的整数中,选择N个出来排列
2014-09-09 15:29
267 查看
#include <IOSTREAM> using namespace std; #define N 3 #define M 5 //从M个不同元素中选取N个出来排列 int x ; int element[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; bool map[M]; //map[i] 为true表示element[i]可用,反之不可用 int count = 0; void backtrack(int t) { if (t>=N) { for(int i=0; i<N; ++i) cout << x[i] << " "; cout << endl; count++; } else { for (int i=0; i<M; ++i) { if (map[i]) { x[t] = element[i]; map[i] = false; backtrack(t+1); map[true]; } } } } int main() { for (int i=0 ; i<M; ++i) map[i] = true; backtrack(0); cout << "总的结果个数为:" << count << endl; return 0; }
相关文章推荐
- 随机生成任意十个整数,分别利用冒泡和选择按从小到大排列。
- 把图片文件夹中的子文件夹以下拉框的形式展示出来。并且选择不同的文件夹显示出各文件夹中的图片
- 把图片文件夹中的子文件夹以下拉框的形式展示出来。并且选择不同的文件夹显示出各文件夹中的图片
- 读取图片,并通过鼠标交互,在图片上选择一块矩形区域,然后把这个矩形区域的子图像显示出来
- 给定一个存放整数的数组,重新排列数组使得数组左边为奇数,右边为偶数
- 前Google人谈团队管理:针对不同员工的情境管理法和如何选择合理的团队规模
- 三个数排序。要求输入三个整数,按逗号隔开,把它们从小到大排列,输出结果用空格隔开。
- js判断手机和pc端选择不同执行事件的方法
- 数据库里取出来结果,按照树来排列。 其实就是数据结构中二叉树的先序遍历
- 给定两个正整数(二进制形式表示)A和B,问把A变为B需要改变多少位(bit)?也就是说,整数A和B的二进制表示中有多少位是不同的?
- 选择后显示不同的颜色和图片的方法
- uva 11076 给n个数字 n个数字的所有排列出来的数 相加 求和
- 解决df和du查出来的已使用空间不同的问题
- 利用Random类产生10个[10,99]之间的随机数,并将这10个随机数在列表框中显示出来,每个数占一项。用户选择某项后,在右边标签中显示所选内容。
- 将EXP出来的数据IMP进不同的表空间
- 根据下拉框选择变化显示不同内容
- 在一个二维数组中,每一行都按照从左到右递增的顺序排列,每一列都按照从上到下递增的顺序排列,请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
- 优势有所不同 悉数发动机气缸排列形式
- 如何设计一个高效算法从N个正整数中,随机选取n个不同的随机数 n<=N
- 如何打造139团队(不同层次人员的选择与培养,大型研发团队,大型敏捷开发团队)