Hello!
For sake of the example, there are sellers who sells cars, where each car has its own price from different seller. A seller also has an additional service price which will always be added for the sellers when a customer buys a car, but is only added once.
The data:
Code:
SellerID 1 2 3
CarID 1 5$ 9$ 4$
2 1$ 2$ -
3 - 2$ 1$
4 3$ - -
+ + +
ServiceCost 5$ 15$ 9$
The values $ are cost of car ID from the seller with the ID (in red)...
This data, matrix, is not static. Service cost is always a value for a seller, it can be 0, but it is always calculated with the price, but only once, even if a buyer purchases/orders 10 cars from 1 seller. Values with a - equals a car that this particular seller does not sell.
For this particular data, the result shall be the cheapest combination:
carID: 1 2 3 4
sellerID: 1 3 1 3
costChosen: 4$ + 1$ + 1$ + 3$
serviceCost: 5$ 9$ 0$ 0$
//Service has already been added for this seller, hence 0$, because car #1 and #3 are sold from same seller, service-cost can only be added once per order of cars. Same with car#2 and #4...
So this would be a totalsum of service-cost (5+9) plus costs of the cars (4+1+1+3) = 23$
It looks like it is "just getting the minimum" at each row, then add the service-cost at the end, but it is not that easy, at all.
For simplicity's sake in this example: carID and sellerID always starts at 0 or 1 and increases by +1. It is just an index from an array of a class-object (Oh really?)...
What I have got so far you ask? Oh, that ain't much, tried solving it without recursion, ended up with loads of loops and if-else-statements...
Any suggestions?
(Bringing up some code later, recursion or maybe not..., so... brb tomorrow )