combination, shortest path algorithms and Python -


i don't know in codding understand basic python. wanted challenge myself writing program solve next - considering store giving 3 options - x$ per day, y$ per month or z$ per year, combination best me assuming want t amount of time?

now, far can understand, have here basic combinatoric question creating tree of combinations, , need of shortest-path algorithms (djikstra, bellman-ford..?) finding best option ("shortests","less expensive")

please me find need approach problem.

this instance of multiple item knapsack problem, time weight, , "value" cost. knapsack size amount of time want. in here want minimize value, equivalent maximizing negatives (assume day "costs -x, month -y, year -z).

this can solved following recursive formula (assuming costs integers or can brought integers), , can implemented rather efficiently using dynamic programming.

d(0,0) = 0 d(x,0) = infinity   x>0 d(x,i) = infinity x < 0 d(x,i) = min{ d(x,i-1), d(x-time[i],i) + cost[i] } 

edit: note not instance of shortest path problem (not directly anyway), because have restriction on path, want find path takes m days, , shortest path algorithms struggle such restrictions.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -