I'm working on the coin change problem with specific coins. Which I understand how to solve, but now there is an additional condition, where each coin has a different weight in grams, and I need to find the number of partitions of a specific sum, but that has to be made with a specific total weight.
I have a set of partitions of coin values that give the required total value, and then a separate set of partitions of weights that sum to the required total weight, and the answer is the intersection of those sets over some function that maps values to weights. Is there some kind of way to efficiently do this? Right now I'm doing it by brute force, where I take each element of whichever partition is smaller and then see if it also meets the other condition. But given how large these sets get, that doesn't seem to be very computationally feasible.
Is there a method to quickly find that intersection or a different approach or way to think about this all together?