I\'m struggling with this algorithm I need to write. I\'m using C#.
Say I have a List
and I have a List
.
I need to
If you allow dupes [a lunch can be in two bags] - as the example suggests you have #bags^#lunches
possibilities.
Each bag has its own unique "choice" which lunch to put
To genereate these possibilities - just "choose" a lunch for a bag, and recursively invoke the algorithm. repeat for each lunch.
pseudo code for generating them:
generateAll(bags,lunches,sol):
if (bags is empty):
print sol
return
bag <- bags.first
bags.remove(bag)
for each lunch in lunches:
sol.append(BagLunch(bag,lunch)
generateAll(bags,lunches,sol)
sol.removeLast()