#include <iostream>
using namespace std;
void printSeq(int num, int a[], int opIndx,int s){
if(num <= 0){
//Display the output
for(int j = 0; j < opIndx; j++)
cout << a[j] << ",";
cout << endl;
return;
}
// s starts from 1 and later it will change to
// 2, 3, 4, 5.
// It is the case$
// 5 = 2 + (3)
// 5 = 3 + (2)
// 5 = 4 + (1)
// 5 = 5 + (0)
for(int i = s; i <= num; i++){
a[opIndx] = i;
printSeq(num-i, a, opIndx + 1, i);
}
}
int main(){
int a[15];
printSeq(5, a, 0, 1);
return 0;
}
ICAjaW5jbHVkZSA8aW9zdHJlYW0+CiAgCiAgdXNpbmcgbmFtZXNwYWNlIHN0ZDsKICAKICB2b2lkIHByaW50U2VxKGludCBudW0sIGludCBhW10sIGludCBvcEluZHgsaW50IHMpewogICAgICBpZihudW0gPD0gMCl7CiAgICAgICAgICAvL0Rpc3BsYXkgdGhlIG91dHB1dAogICAgICAgICAgZm9yKGludCBqID0gMDsgaiA8IG9wSW5keDsgaisrKQogICAgICAgICAgICAgIGNvdXQgPDwgYVtqXSA8PCAiLCI7CiAgICAgICAgICBjb3V0IDw8IGVuZGw7CiAgICAgICAgICByZXR1cm47CiAgICAgIH0KICAKICAgICAgLy8gcyBzdGFydHMgZnJvbSAxIGFuZCBsYXRlciBpdCB3aWxsIGNoYW5nZSB0bwogICAgICAvLyAyLCAzLCA0LCA1LgogICAgICAvLyBJdCBpcyB0aGUgY2FzZSQKICAgICAgLy8gNSA9IDIgKyAoMykKICAgICAgLy8gNSA9IDMgKyAoMikKICAgICAgLy8gNSA9IDQgKyAoMSkKICAgICAgLy8gNSA9IDUgKyAoMCkKICAgICAgZm9yKGludCBpID0gczsgaSA8PSBudW07IGkrKyl7CiAgICAgICAgICBhW29wSW5keF0gPSBpOwogICAgICAgICAgcHJpbnRTZXEobnVtLWksIGEsIG9wSW5keCArIDEsIGkpOwogICAgICB9CiAgfSAgIAogIAogIGludCBtYWluKCl7CiAgICAgIGludCBhWzE1XTsKICAgICAgcHJpbnRTZXEoNSwgYSwgMCwgMSk7CiAgICAgIHJldHVybiAwOwogIH0=
1,1,1,1,1,
1,1,1,2,
1,1,3,
1,2,2,
1,4,
2,3,
5,