atlasworld's blog

By atlasworld, history, 6 years ago, In English

can anyone please explain how this problem will reduce to 0/1 Knapsack problem after increasing each t[i] by 1?

why we are increasing t[i] by 1 ?

Tags #dp
  • Vote: I like it
  • -8
  • Vote: I do not like it

| Write comment?
»
6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Cause when we buy i-th item we will have this item plus t[i] items, in sum we have t[i]+1 item instead t[i]

  • »
    »
    6 years ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    ok ..

    so our number of items increase by t[i]+1 if we but i_th item , but how will we reduce it to knapsack equation , what will be the dp state & base case ?

    • »
      »
      »
      6 years ago, # ^ |
      Rev. 2   Vote: I like it 0 Vote: I do not like it

      U can use my solution to better understand 40091182 There dp[i][j] means minimum cost of j items when we already looked through i items

      • »
        »
        »
        »
        6 years ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        what does dp[i][j] means in ur code ?

        i can be the item that you are currently processing ?

        what does j refers here ? can you please tell me a bit !

        • »
          »
          »
          »
          »
          6 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          There dp[i][j] means minimum cost of j items when we already looked through i items