#include <iostream>
#include <cmath>
#include <list>
using namespace std;
class decompose
{
private:
 int _weight;
 int sum;
 int n;
 int _depth;
 int *_result;
 int _value;
 void ShowResult();
public:
 decompose( int sum, int n ):sum(sum), n(n), _value(sum), _depth(n), _weight
(0){
  _result = new int[n];
 };
 ~decompose() { delete _result; }
 void run();
};
void decompose::run()
{
 if( _depth < 2 )
  return;
 if( _depth == 2 )
 {
  for( int i = 0; i <= _value / 2; i++ )
  {
   if( _weight == 0 && i == 0 ) continue;
   _result[n-2] = i + _weight;
   _result[n-1] = _value - i + _weight;
   ShowResult();
  }
  _result[n-2] = 0;
  _result[n-1] = 0;
  return;
 }
 else
 {
  for( int i = 0; i <= _value / _depth; i++ )
  {
   if( _weight == 0 && i == 0 ) continue;
   _result[n - _depth] = i + _weight;
   _weight += i;
   _value -= i * _depth;
   _depth--;
   run();
   _depth++;
   _value += i * _depth;
   _weight -= i;
   if( _depth == n ) _weight = 0;
  }
 }
}
void decompose::ShowResult()
{
 for( int i = 0; i < n; i++ )
  cout<<_result[i]<<'\t';
 cout<<endl;
}
int main()
{
 decompose dec(10, 4);
 dec.run();
}

���薪��
1       1       1       7
1       1       2       6
1       1       3       5
1       1       4       4
1       2       2       5
1       2       3       4
1       3       3       3
2       2       2       4
2       2       3       3

����遣��馗��慕����要��要���械慕���ShowResult()�某�
�����校�������涂����恕�
--
    �X�T�T�T�j�T�T�T�T�j�T�T�j�T�T�j�T�T�T�T�T�T�j�T�T�T�T�T�T�[
    �U小�����U�b�[�i�X�a�b�[�l�X�e�^�T�T�T�e�X�e�^�e�X�T�T�T�e�U
    �d�T�Y�X�a�X�p�a�U�b�[�^�j�a  �b�j�T�e�X�p�[�X�T�g�V�T�T�T�g          
    �U�b�T�a�X�a�^�e�m�T�m�e�U  �b�T�m�T�T�a�d�a�^�e�^�[�夜����U
    �^�T�T�T�m�T�T�T�T�T�T�T�m�T�T�T�T�T�T�T�m�T�T�T�T�m�T�T�T�a
                                  ��为�翻山越�,却���目��景�� 
�� ��源:���野��峡�站 bbs.nankai.edu.cn��[FROM: 159.226.251.20]