Блог пользователя gXa

Автор gXa, история, 7 лет назад, По-английски

A tree is given in which each edge is having some weight associated with it and you are given a number K.

So starting from root in K-steps how much maximum weight you can collect. You can traverse in any direction either from parent to child or child to parent. You can visit a node multiple times.

~~~~~ ~~~~~

Spoiler
  • Проголосовать: нравится
  • -2
  • Проголосовать: не нравится

»
7 лет назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

I have not formally proved this, but say we use the edges e1, e2, e3, ..., ek (these are the weights). So sum over all ei is less than k * max(ei), i.e, it is better to repeat the max edge k times. So this may lead to a greedy algorithm. For each edge, if the depth of the node is d, add the weight upto that depth, and then add the edge k - d times. Find the maximum for all edges.