Selecting A combination of minimum cost

前端 未结 5 1636
天命终不由人
天命终不由人 2020-12-10 09:07

I have data of different items in a different restaurants

    Rest    Item     Price
    ----------------------
    ABC     dosa      14
    ABC     idly             


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-10 09:42

    A sketch of one possible greedy algorithm is:

    1. Iterate through all unary offers (e.g. dosa, idly or upma) to find the minimum of each.
    2. Iterate through all binaray (e.g. idly+upma) / tertiary (...) offers, compare if it's cheaper than the unary offers and replace if so.

    You will have to code the offer deparsing still, but it shouldn't be that hard. This algorithm will find good, but not necessary the best solution, and might work on very small smaples.

    Actually, your problem compares to the Rucksack or TSP problems, which are NP-complete and thus only solvable in exponentially time. If you want a solution for that, consider reading a lot of papers and coding even more. That's the holy grail of computer science. ;-)

    UPDATE: On request of the TO here's some exponentially pseudocode sketch:

    foreach restaurant
        create a list of all possible combinations of the offers // here's the exp!
        filter those combinations that hold more/less than 1 dosy/idly/umpa
        select minimum of the remaining ones
    

    Comment: This is really ugly, yuk! :-(

提交回复
热议问题