0-1 knapsack problm

WHY CANT I SOLVE THIS USING 1D DP INSTEAD OF 2D DP

CAUSE I THINK
IF THE WINE PROBLEM ,WHOSE ANS DEPENDED ON THE INDEX OF PICKING UP OF WINE AND THE YEAR CAN BE SOLVED IN 1D DP
https://www.geeksforgeeks.org/maximum-profit-sale-wines/

THEN WHY NOT THIS
https://hack.codingblocks.com/contests/c/512/257

and how will i know whether 2d dynamic programming is to be applied or 1d dynamic programming
in questions
can u please explain with example

Deciding between 1d or 2d DP basically depends on the number of parameters that you need to work upon.

You can see the code here of 0-1 knapsack with 1d array
code link :https://ide.codingblocks.com/s/43101

Refer to this video for practice and examples.

thanks bhaiya
i earlier tried to implement 1 d dp but was getting only one output for all values

1 Like

i have seen that video sachin bhaiya and i got the way of solving it via 2d dp but i wanted to solve it via 1d dp

found my mistake and working on it :sweat_smile:

https://ide.codingblocks.com/s/44224

https://hack.codingblocks.com/contests/c/512/257

Oh that’s great! :slight_smile:

Happy coding :slight_smile: