C++ 代码
#include<iostream>
#include<algorithm>
using namespace std;
const int N =110;
int path[N];
int depth,n;
bool dfs(int u)
{
if(u==depth)
return path[u-1] == n;
bool st[N]={0};
for(int i=u-1; i>=0 ;i--)
for(int j=i; j>=0 ; j-- )
{
int sum= path[i] + path[j];
if(sum>n || sum<=path[u-1] || st[sum]) continue;
st[sum] = true;
path[u]= sum;
if(dfs(u+1))
return true;
}
return false;
}
int main()
{
path[0]=1;
while(cin >> n, n)
{
depth=1;
while(!dfs(1))
depth++;
for(int i=0;i<depth;i++)
cout << path[i] << ' ';
cout <<endl;
}
return 0;
}