I am trying to solve this problem from SPOJ, it’s a dynamic programming problem, but I’m having trouble visualizing the recursive step. I believe it’s similar to a knapsack, but here there are two constraints of Oxygen and Nitrogen.
Here is the link: http://www.spoj.pl/problems/SCUBADIV/
This should work I think:
Note that the
forloops must go from the max down to the values of the current cylinder, otherwise you allow a cylinder to be used more than once.The problem constraints are very small and I think this should work.