0

If you have a unweighted directed graph with possible cycles, what algorithm would you use to find the longest path without visiting the same node twice? Also, there are multiple starting nodes...

The real problem I am trying to solve is the following:

All values are positive integers:

A1 = [a1, a2, ..., an]

B2 = [b1, b2, ..., bn]

A person starts at ai. In order to live another day, the person must find an aj (i != j) that is greater than or equal to bi (you do not 'keep' the difference of the two). Once the person selects aj, the must do the same with bj and ak. The goal is to live as long as possible, and each time you land on an ai, counts as a new day.

How would you solve a problem like this?

1 Answers1

0

The longest path problem is $\mathsf{NP}$-complete, so there is no known polynomial algorithm.

It can be solved in exponential time using dynamic programming.

Nathaniel
  • 15,071
  • 2
  • 27
  • 52