#include<iostream>
using namespace std;
void Recursion(short*&arr,short&len,short starter,short left_value)
//输入数组,盘子总数,当前要放苹果的盘子序号,剩下要分配的苹果数
{
if(starter>=len&&left_value>0)
{
return;
}
if(left_value==0)
{
for(short j=0;j<starter;j++)
{
cout<<arr[j]<<',';
}
for(j=starter;j<len;j++) cout<<0<<',';
cout<<endl;
return;
}
for(short i=0;i<=left_value;i++)
{
arr[starter]=i;
Recursion(arr,len,starter+1,left_value-i);
}
}
void Distribution(short apple,short dish)
{
short*arr=new short[dish];
memset(arr,0,sizeof(short)*dish);
Recursion(arr,dish,0,apple);
delete arr;
}
int main()
{
cout<<"输入苹果数:";short a;cin>>a;
cout<<"输入盘子数:";short p;cin>>p;
Distribution(a,p);
return 0;
}