pingu,
<script>
let A = [15.8, 1.2, 1.1, 1.0, 0.9, 0.8, 0.7, 0.6, 0.6, 0.6, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5];
let K = 2;
let arr = Combination(A, K);
function Combination(A, K) {
A.sort((a, b) => a - b);
let local = [], pr = [];
unique_combination(0, 0, K, local, A, pr);
return pr
}
function unique_combination(l, sum, K, local, A, pr) {
if (sum == K) {
pr.push(local.slice(0).sort((a, b) => b - a));
}
for (let i = l; i < A.length; i++) {
if (sum + A[i] > K)
continue;
if (i > l && A[i] == A[i - 1])
continue;
local.push(A[i]);
unique_combination(i + 1, sum + A[i], K, local, A, pr);
local.pop();
}
}
document.write(`<pre>${JSON.stringify(arr)}</pre>`);
</script>