Tuples that sum to 1 (for large n)

Hi! I am trying to find all the possible weights that sum to one:

weights = Table[0.05*i,{i,0,20}] (* list of weights *)
n= 2
alltuples =Tuples[weights,n]; (*generate all tuples *)
Length[alltuples] (* number of tuples there are *)
Select[alltuples, Plus@@#==1&] (*list of all the tuples that sum to one *)

So this works and I get all the permutations that add to 1. However I want this done with n = 9 and n=10. This is not possible as it crashes (due to memory issues). You can try setting n=9 and the code won’t work.

Is there a more elegant way to approach this problem? I guess I am using a brute force method which is not appropriate given the size of the problem.

Thanks!
Priyan.

Hi. You could try using IntegerPartitions[n,k].
eg.,

f[n_,k_] := IntegerPartitions[n, k]/n

f[20,2] // N

{{1.}, {0.95, 0.05}, {0.9, 0.1}, {0.85, 0.15}, {0.8, 0.2}, {0.75, 0.25}, {0.7, 0.3}, {0.65, 0.35}, {0.6, 0.4}, {0.55, 0.45}, {0.5, 0.5}}

Length[f[20,10]]

530

Regards