Effectively find the smallest sum paths

This is a big question, but I'm a little stuck!

I am wondering if there is a name for this problem or the like.

I probably complicate the search for a solution too much, but I cannot come up with a way without a full exhaustive brute force search (my current implementation). This is not acceptable for the application.

I am wondering if there are ways to simplify this problem or implementation strategies that I could use (language / tool selection is open).

Here is a brief description of the problem:

Given n sequences of length k :

a = [0, 1, 1] == [a1, a2, a3]
b = [1, 0, 2] == [b1, b2, b3]
c = [0, 0, 2] == [c1, c2, c3]

find paths of length k through sequences as such (I will give examples starting with a1, but I hope you get the idea that the same paths should be obtained from b1, c1)

a1 -> a2 -> a3
a1 -> b1 -> b2
a1 -> b1 -> a2
a1 -> b1 -> c1
a1 -> c1 -> c2
a1 -> c1 -> a2
a1 -> c1 -> b1

, :

a1 -> a2 -> a3 == 2
a1 -> b1 -> b2 == 1
a1 -> b1 -> a2 == 2
a1 -> b1 -> c1 == 1
a1 -> c1 -> c2 == 0
a1 -> c1 -> a2 == 1
a1 -> c1 -> b1 == 1

, a1 β†’ c1 β†’ c2 .

EDIT:

, . , node a1 b2, b2 node (b1).

+4
2

, A, . (n+1)x(k+1) , A[_][0] = 0

, DP :

f(x,y,z) = min  { f(i,y,z-1) | x < i <= n} [union] { f(i+1,0,z) }  + A[x][y]
f(_,_,0) = 0
f(n,k,z) = infinity for each z > 0

:. ( ) - , .
A[_][0], , , A[_][0] = 0.

:
, f(_,_,_) O(n*k^2), O(n) - O (1) , 1. O(n*k^2) - .


(1) min{x1,x2,x3,...,xk} = min{x_k, min{x1,...,k_k-1}}, min{x1,...,k_k-1}

+1

A *.

  • 0s
  • m
    • n m     4. n = n min ( n , n ).
  • 0,0 -

** .

0

Source: https://habr.com/ru/post/1524337/


All Articles