询问一个输出全组合算法的时间复杂度
询问一个输出全组合算法的时间复杂度,最好能说明一下怎么得来的,谢谢~~
#include <iostream>#include <conio.h>using namespace std;bool L3( unsigned int &end, unsigned int staticStart, unsigned int &staticEnd ){ //终止判断 if( staticEnd >= end ){ return false; } unsigned int i = 0; unsigned int j = 0; for( i=staticEnd+1; i<=end; i++ ){ //1.输出Static Head for( j=staticStart; j<=staticEnd; j++ ){ cout << j; } //2.输出变化值 cout << i << endl; } staticEnd++; return true;}bool L2( unsigned int &end, unsigned int n ){ if( n > end ){ return false; } cout << n << endl; unsigned int i = 0; unsigned int iend = end - i; unsigned int staticEnd = n; while( L3( end, n, staticEnd ) ){ ; } return true;}bool L1( unsigned int &end ){ if( end<1 ){ return false; } unsigned int i = 0; for( i=1; i<=end; i++ ){ L2( end, i ); } return true;}int main( void ){ unsigned int i = 0; for( i=1; i<=10 ;i++ ){ system( "CLS" ); cout << "【" << i << "】的全组合数:" << endl; cout << "--------------" << endl; L1( i ); cout << "--------------" << endl; cout << "按任意键继续..." << endl; _getch( ); } cout << "END" << endl; _getch( ); return 1;}
for( i=staticEnd+1; i<=end; i++ ){ //1.输出Static Head for( j=staticStart; j<=staticEnd; j++ ){ cout << j; } //2.输出变化值 cout << i << endl; }