You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include<iostream>
|
|
|
|
|
#include<string.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
void Combine(int arr[], int n, int m)
|
|
|
|
|
{
|
|
|
|
|
if(m > n)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int* pTable = new int[n]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>buf<75><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰm<C7B0><6D><EFBFBD><EFBFBD>1
|
|
|
|
|
memset(pTable,0,sizeof(int)*n);
|
|
|
|
|
for(int i = 0; i < m; ++i)
|
|
|
|
|
pTable[i] = 1;
|
|
|
|
|
|
|
|
|
|
bool bFind = false;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < n; i++) //<2F><>ӡ<EFBFBD><D3A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
if(pTable[i])
|
|
|
|
|
cout << arr[i] << "\t";
|
|
|
|
|
}
|
|
|
|
|
cout << endl;
|
|
|
|
|
|
|
|
|
|
bFind = false;
|
|
|
|
|
for(int i = 0; i < n-1; i++)
|
|
|
|
|
{
|
|
|
|
|
if(pTable[i]==1 && pTable[i+1]==0)
|
|
|
|
|
{
|
|
|
|
|
swap(pTable[i],pTable[i+1]); //<2F><><EFBFBD><EFBFBD>10Ϊ01
|
|
|
|
|
bFind = true;
|
|
|
|
|
|
|
|
|
|
if(pTable[0] == 0) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һλΪ0<CEAA><30><EFBFBD><EFBFBD>iλ<69><CEBB>֮ǰ<D6AE><C7B0>1<EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD><DFA3><EFBFBD>Ϊ1<CEAA><31><EFBFBD><EFBFBD>iλ<69><CEBB>֮ǰ<D6AE><C7B0>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ߣ<EFBFBD><DFA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
for (int k=0, j=0; k < i; k++) //O(n)<29><><EFBFBD>Ӷ<EFBFBD>ʹ1<CAB9><31>ǰ0<C7B0>ں<EFBFBD>
|
|
|
|
|
{
|
|
|
|
|
if(pTable[k])
|
|
|
|
|
{
|
|
|
|
|
swap(pTable[k],pTable[j]);
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} while (bFind);
|
|
|
|
|
delete [] pTable;
|
|
|
|
|
}
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
int arr[] = {1,2,3,4,5,6};
|
|
|
|
|
Combine(arr,sizeof(arr)/sizeof(int),3);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|