/////////在网上找了个程序,运行了下,还可以,但具体的实现过程还没看懂,大家一起看看。。
#include<iostream> 
using namespace std; 
//////////////////// 
static int n; 
int *a; 
static long total=0; 
void output(int s) 
{ 
    int i=1; 
    cout<<"n: "<<n<<endl; 
    cout<<"a["<<i<<"]: "<< a[i] <<'\t'; 
    ////////////// 
    for(i=2; i<=s; i++) 
        cout<<"a["<<i<<"]: "<<a[i]<<'\t'; 
    cout<<endl; 
} 
///////////////// 
int filter(int s) 
{ 
    int i,j; 
    if( s==1 ) 
        return -1; 
    for( i=s; i>0; i-- ) 
        for( j=1; j<i;j++ ) 
            if( a[i]==a[j] ) 
                return -1; 
        return 0; 
} 
//////////////////////////////////// 
void dfs( int d, int low, int rest ) 
{ 
   int i; 
   if(rest ==0) 
   { 
       if(filter(d-1)==0) 
       { 
           total++; 
           output(d-1); 
       } 
   } 
   if( low > rest ) 
   { 
       return; 
   } 
   /////////////////////// 
   for( i=low; i<=rest; i++ ) 
   { 
   a[d]=i; 
   //cout<<"i: "<<i<<endl; 
   dfs(d+1,i, rest-i); 
   //cout<<"ii: "<<i<<endl; 
   } 
} 
/////////////////////////////////////// 
/////////////////////////////////////// 
int main() 
{ 
  int num; 
  cout<<"input the num: "; 
  cin>>num; 
  ///// 
  n=num; 
  a=new int [n+1]; 
  // 
  dfs(1,1,n); 
  cout<<"total: "<<total<<endl; 
  cout<<endl; 
  delete []a; 
  return 0; 
}