*Knapsack problem*, only you don't need to find the optimal solution, just need to list them all: https://en.wikipedia.org/wiki/Knapsack_problem[^].

From this article, you can find the overview of known solutions. Not all of them will be helpful for you, because you need to list all solutions not exceeding the maximum total value, not the best one. Anyway, as the problem is found to be

*NP-complete*(https://en.wikipedia.org/wiki/NP-completeness[^]), you have nothing to do but try all possible solutions, so you just need to list them.

Let's call the "solution" the set of numbers representing the number of caught fish of each species. So, you need to fill in the array of integers representing the number of caught fish with numbers 0 to N and choose only the solution with total point amount not exceeding the allowed maximum for total amount.

First, I would find the maximum numbers of caught fish of each species, not exceeding the maximum total amount in the case you catch fish of only this species. Having N species i = 1... N, your maximum fish numbers for each species will be inside the ranges

species

_{0}: [ 0.. Max

_{species0}]

species

_{1}: [ 0.. Max

_{species1}]

...

species

_{N-1}: [ 0.. Max

_{speciesN−1}]

The total number of variants to check up won't exceed the number

(Max

_{species0}+1) * (Max

_{species1}+1) *... (Max

_{speciesN−1}+1).

You can try all those combinations in some order, that's it.

The problem is not about the loops at all, it's about developing the algorithm and perhaps developing a more efficient algorithm, because brute-force one seems quite obvious...

—SA

That means for each possible number of perch 1~4 you have to find all combinations of trout and pickerel that could possibly "fit" in the point-limit.

The problem look intimidating, but is rather easy.