#include <iostream>
using namespace std;
int n, stack[100];
int getMax(int level) {
int max = 0;
for(int i = 1; i <= level-1;++i) {
if(stack[i]>max) {
max = stack[i];
}
}
return max;
}
void partition(int level) {
if(level == n + 1) {
for(int i = 1; i <= level-1;++i) {
cout<<stack[i]<<" ";
}
cout<<endl;
} else {
stack[level] = 0;
while(stack[level]<getMax(level)+1) {
stack[level] += 1;
partition(level+1);
}
}
}
int main(int argc, char const *argv[]) {
n = 5;
partition(1);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBuLCBzdGFja1sxMDBdOwoKaW50IGdldE1heChpbnQgbGV2ZWwpIHsKCWludCBtYXggPSAwOwoJZm9yKGludCBpID0gMTsgaSA8PSBsZXZlbC0xOysraSkgewoJCWlmKHN0YWNrW2ldPm1heCkgewoJCQltYXggPSBzdGFja1tpXTsKCQl9Cgl9CQoJcmV0dXJuIG1heDsKfQoKdm9pZCBwYXJ0aXRpb24oaW50IGxldmVsKSB7CiAgICAgaWYobGV2ZWwgPT0gbiArIDEpIHsKICAgICAJIGZvcihpbnQgaSA9IDE7IGkgPD0gbGV2ZWwtMTsrK2kpIHsKICAgICAgICAgICBjb3V0PDxzdGFja1tpXTw8IiAiOwogICAgICAgICB9CiAgICAgICAgIGNvdXQ8PGVuZGw7CiAgICAgfSBlbHNlIHsKICAgICAgICAgc3RhY2tbbGV2ZWxdID0gMDsKICAgICAgICAgd2hpbGUoc3RhY2tbbGV2ZWxdPGdldE1heChsZXZlbCkrMSkgewogICAgICAgICAgICAgICBzdGFja1tsZXZlbF0gKz0gMTsKICAgICAgICAgICAgICAgcGFydGl0aW9uKGxldmVsKzEpOwogICAgICAgICB9CiAgICAgfQp9CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciBjb25zdCAqYXJndltdKSB7CgogIG4gPSA1OwogIHBhcnRpdGlvbigxKTsKCiAgcmV0dXJuIDA7Cn0K