Динамика → Разбор Маскарад 1
13 май
This problem is typical knapsack but with a little spice inside.
First of all , let assume F(n,l) - the minimal amount of money needed to buy n-meters material if some amount of material was bought in l-th shop. Then it means , that you can buy in l-th shop 0-meters of material and 0-meters in l-1 shops or 1-meter of material and 0-meters in l-1 shops and so on. By this way we can easily say that : F(n, l) is min(k is [1...r]) (f(n, k) + F(n-1, r-k));
if you sure that your task is solved try this test 2 70 7 50 1 100 7 8 6 10 Complexity: O(n*(l+p)^2) and after that you can be sure! thanks in advance