abhinav700's blog

By abhinav700, history, 12 months ago, In English

Are there any good resources which describe the solution to following pattern problems:

Suppose You are given a tree of N nodes. You are given two arrays of size N: cost, value, where value[i] represents the money that you get from selling Node i, and Cost[i] represents the budget spent to buy i. You are also given a budget Variable B. Total money spent to buy nodes cannot be more than B. Find the maximum profit you can get.

Recently encountered this problem. Tried going through the solution, but none of them give the proper explanation for this. Just some description of the code.

The leetcode problem based on this pattern: Link

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
12 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

USACO guide has a section on tree DP, try doing the practice problems

https://usaco.guide/gold/dp-trees