#include #include using namespace std; bool next_partition(int &n, vector &a) { if (n == 1) { return false; } int sum = a[n - 1]; n = n - 2; while (n > 0 && a[n - 1] == a[n]) { sum += a[n]; n--; } a[n]++; sum--; n++; while (sum > 0) { a[n] = 1; sum--; n++; } return true; } void all_partitions(int n) { vector a(n, 1); do { for (int i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl; } while (next_partition(n, a)); } int main(void) { int n; cin >> n; all_partitions(n); return 0; }