# 排列组合的算法

{
{1,2,3,4}，
{1,2,3,4}，
{1,2,3,4}，
{1,2,3,4}，
}从每组数据中取出一个，组合成一个新的数据，

----------------------------------------------------------------------------------------------

#include <iostream>
using namespace std;

int main()
{
int x[4][4]=
{
{1,2,3,4},
{5,6,7,8},
{1,2,3,4},
{1,2,3,4},
};
for(int a=0; a<4; ++a)
for(int b=0; b<4; ++b)
for(int c=0; c<4; ++c)
for(int d=0; d<4; ++d)
cout<<"{"<<x[0][a]<<x[1][b]<<x[2][c]<<x[3][d]<<"}"<<endl;
return 0;
}

----------------------------------------------------------------------------------------------------

#include <iostream>
using namespace std;

const int count=3;
int a[count][count];
int p[count];
int n;

void f()
{
int i;
if (n<0)
{
return;
}
for (int i=0; i<count; i++)
{
cout << a[i][p[i]];
}
cout <<endl;

p[n]++;
if (p[n]>=count)
while (p[n]>=count)
{
p[n]=0;
n--;
p[n]++;
if (n<0)
{
return;
}
}
n = count-1;
f();
}

main()
{
for (int i=0; i<count; i++)
for (int j=0; j<count; j++)
a[i][j] = j+1;
n = count-1;
f();
}

-------------------------------------------------------------------------------------------------------------------

#include <IOSTREAM>
#include <VECTOR>

using namespace std;

typedef
unsigned int
Counter;
typedef
vector<Counter>
CounterArrayType;
typedef
void (*DoThing)(CounterArrayType &);

Counter P(Counter Depth, const CounterArrayType & Endians, DoThing ThingToDo);

void ATestThing(CounterArrayType &);

int main(int argc, char* argv[])
{
int n = 3;
CounterArrayType Endian(size_t(n), 4);
cout << P(n, Endian, ATestThing);
cin >> n;
return 0;
}

Counter P(Counter Depth, const CounterArrayType & Endians, DoThing ThingToDo) {
Counter atDepth = 0, runTimes = 0;
bool Finished = false;
vector<Counter> LoopVar( Depth, 0 );
while (!Finished) {
atDepth = 0;
(*ThingToDo)(LoopVar);
++runTimes;
while (++LoopVar[atDepth] == Endians[atDepth]) {
LoopVar[atDepth++] = 0;
if (atDepth == Depth) {
Finished = true;
break;
}
}
}
return runTimes;
}

void ATestThing(CounterArrayType & vTest) {
static CounterArrayType::iterator itvTest;
cout << '[' << vTest.size() << ']';
for(itvTest = vTest.begin(); itvTest != vTest.end(); ++itvTest )
cout << ' ' << *itvTest;
cout << endl;
}

Counter P(Counter Depth, const CounterArrayType & Endians, DoThing ThingToDo)

#### 排列组合算法总结（含Java实现）

2017-06-06 17:22:55

#### 快速组合排列算法

2015-10-27 11:57:16

#### 终于有个高效率的排列组合算法

2006-05-28 21:54:00

#### C++：排列组合算法

2016-08-20 22:47:37

#### c++ 排列组合算法，代码简单

2010年05月16日 5KB 下载

#### 排列组合算法实现--基于JS

2017-05-13 14:31:09

#### 排列组合公式及排列组合算法

2014-03-27 09:38:32

#### 排列组合算法1：生成全部有序列

2007-03-06 15:17:00

#### 【数据结构与算法】关于排列组合

2017-01-05 19:59:57

#### 高效率的排列组合算法（java实现）

2009-01-01 16:40:00