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

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

there are 'n' nodes and 'm' edges in a graph. each node may or may not contain certain number of a item. all nodes have same item but different number of that item.

we have to go from source to destination in minimum time collecting 'k' number of this item. each edge is weighted,weights may or may not be same. there are no self loops. edges are bidirectional.

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

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

Let's all nodes have exactly one item, 'k' = 'n', weight of each edge exactly 1, source and destination is the same node. Then, collecting 'k' items in minimum time = 'n' means to find the Hamiltonian cycle for Hamiltonian graphs. So this is NP-hard problem.

I think it's pretty simple to make a dp solution in 2^n * n^2. Like dp[mask][x][y] = minimum time to collect x item, visit nodes stored in 'mask' and ended in node 'y'.