|
|
|
| Программка зависает в бесконечном цикле...
#include <QCoreApplication>
#include <iostream>
using namespace std;
void GetPermutations(int tbl[2][8], int m, int n)
{
if(n!=0)
{ bool flag=false;
for(int i=0;i<8;i++)
{
for(int j=0;j<8;j++)
{
for(int k=0;k<8;k++)
{
if(tbl[0][k]==i || tbl[1][k]==j)
flag=true;
}
if(!flag)
{
tbl[0][m]=i;
tbl[1][m]=j;
GetPermutations(tbl, m+1, n-1);
for(int h=m;h<8;h++)
{
tbl[0][h]=-1;
tbl[1][h]=-1;
}
}
flag=false;
}
}
}
else{
for (int i=0;i<8;i++) { cout<<"("<<tbl[0][i]<<", "<<tbl[1][i]<<") ";
cout<<"\n----------\n";
}
}
}
int main()
{ int table[2][8];
for(int i=0;i<8;i++){
table[0][i]=-1;
table[1][i]=-1;
}
GetPermutations(table, 0, 8);
return 0;
}
|
| |
|
|