[Edito], y si queda algo pasa para la versión beta.
Código C++:
Ver original#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
struct cmp {
bool operator() (std::vector<int> a, std::vector<int> b)
{
std::sort(a.begin(), a.end());
std::sort(b.begin(), b.end());
return a < b;
}
};
typedef std::set<std::vector<int>, cmp> sstype;
sstype& permutar(std::vector<int> p, std::vector<int> f, int suma)
{
static sstype ss;
if(suma == std::accumulate(p.begin(), p.end(), 0)) {
ss.emplace(p.begin(), p.end());
return ss;
}
for(size_t i = 0; i < f.size(); ++i) {
auto ppio = p;
ppio.push_back(f[i]);
auto fin = f;
fin.erase(fin.begin() + i);
permutar(ppio, fin, suma);
}
return ss;
}
int main()
{
std::vector<int> v{8, 2, 3, 3, 6, 4};
const int suma = 6;
auto ss = permutar(std::vector<int>{}, v, suma);
for(auto& i : ss) {
for(auto& j : i)
std::cout << j << ' ';
std::cout << '\n';
}
}