(用C++解决)(1)从1到30内 任选6个数排列,(2)要求6个数加起来 在90到110之间,(请问一共有多少组数

来源:百度知道 编辑:UC知道 时间:2024/05/15 15:47:56
,(3)6个数不能全是偶数,或者全是奇数,(4)不能出现3连数,4连数,5连数,6连数。
请问程序怎么编?

1.组合
从1到30内 任选6个数排列
C(30,6)种组合

2.去除没用的
(1)6个数加起来 在90到110之间
(2)6个数不能全是偶数,或者全是奇数
(3)全排列然后,不能出现3连数,4连数,5连数,6连数。

这里提供一个全排列的方法:
// output all permutations of n elements

#include <iostream.h>

template<class T>
inline void Swap(T& a, T& b)
{
T temp = a; a = b; b = temp;
}

template<class T>
void Perm(T list[], int k, int m)
{// Generate all permutations of list[k:m].
int i;
if (k == m) {// list[k:m] has one permutation, output it
for (i = 0; i <= m; i++)
cout << list[i];
cout << endl;
}
else // list[k:m] has more than one permutation
// generate these recursively
for (i = k; i <= m; i++) {
Swap(list[k], list[i]);
Perm(list, k+1, m);
Swap(list[k], list