_aditya's blog

By _aditya, history, 6 years ago, In English

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.

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

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

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'.