jeudi 19 avril 2018

Select a number from two sets each that the sum of their multiplication equals to a specific sum

I have two sets like A={0,1,2,...,n} and B={3,6,10,15}, a constant s, and a specified number $n$ which belongs to natural numbers set. I want to find a/all combinations that satisfy a_1*b_1+a_2*b_2+\dots+a_n*b_n>=s

For example, if s=25, n=2 each of following answers is acceptable 1*10+1*15 or 2*10+1*6 or 0+2*15

If I didn't have the second set it would be easy because the problem reduces to producing random partitions with predetermined sum s as introduced in here

How should I efficiently implement this in python? any mathematical way to do it? It also reminds me of some kind of equation but I'm not sure what I should search for. I appreciate any hint.




Aucun commentaire:

Enregistrer un commentaire