标签:
#include <iostream> #define MAXN 100 #define min __min using namespace std; int tem[MAXN]; int _min[MAXN]; int n; int min; void DFS(int num,int index); int main() { //freopen("acm.acm","r",stdin); int i; int k; int index; while(cin>>n,n) { if(n == 1) { cout<<1<<endl; continue; } index = 0; min = 100; tem[index] = 1; index = 1; for(i = index-1; i >= 0; -- i) { if(tem[i] + tem[index-1] <= n) { tem[index] = tem[i]+tem[index-1]; DFS(tem[index],index+1); } // else // break; } for(i = 0; i < min-1; ++ i) { cout<<_min[i]<<" "; } cout<<_min[i]; cout<<endl; } } void DFS(int num,int index) { if(index >= min) { return; } if(num == n) { int i; if(min > index) { for(i = 0; i < index; ++ i) { _min[i] = tem[i]; } min = index; } return; } int i; int k; for(i = index-1; i >= 0; -- i) { if(tem[i] + tem[index-1] <= n) { tem[index] = tem[i]+tem[index-1]; DFS(tem[index],index+1); } //else //{ // return; //} } }
标签:
原文地址:http://www.cnblogs.com/gavinsp/p/4566738.html