Написал код, который раскладывает на слагаемые число, их нужно в порядке НЕУБЫВАНИЯ расположить. вот код:
#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>
#define N 5
using namespace std;
bool comp(int a, int b)
{
return (a < b);
}
vector<int> x(40);
void Partitions(int pos, int max, int number )
{
int i;
if (!number)
{
int m = x.size();
// Number of columns assuming it’s a square matrix
for (i = 0; i < pos; i++) {
//sort(x.begin(), x.begin() + pos);
//sort(x.begin() + i, x.begin());
cout << x[i] << " ";
}
cout << endl;
//nth_element(x, x + 4, x + 7, comp);
}
else
for (i = min(number,max); i >= 1 ; i--)
{
x[pos] = i;
Partitions(pos + 1, i, number - i);
}
}
int main()
{
int n;
cin >> n;
Partitions(0, n, n);
return 0;
}
Нужно, чтобы выводилось вот так:
Прошу, помогите пожалуйста