fork download
#include<bits/stdc++.h>
using namespace std;


vector<vector<int>> v;
int arr[33];
int l = 0, r = -1;

void dfs(int n, int k){
//	cout << n << ' ' << k << '\n';
	if(n == 0){
		vector<int> tmp;
		for(int i = l; i <= r; i ++) tmp.emplace_back(arr[i]);
		v.emplace_back(tmp);
		return;
	}
	else{
		for(int i = min(n,k); i >= 1; i --){
			arr[++r] = i;
			dfs(n-i, min(k, i));
			r--;
		}
	}
	
}

int main(){
	int n;
	cin >> n;
	dfs(n, n);
	cout << v.size() << '\n';
	for(auto i : v){
		cout << i[0];
		for(int j = 1; j < i.size(); j ++){
			cout << ',' << i[j];
		}
		cout << '\n';
	}
}
Success #stdin #stdout 0s 5304KB
stdin
5
stdout
7
5
4,1
3,2
3,1,1
2,2,1
2,1,1,1
1,1,1,1,1