100 row numbers to find the shortest path I got a question that I have 100 rows of the number, as in the picture that continuous to 100 rows. There is a sequence by starting from
the top, and then for each integer walk to the left or right value in the row beneath. That is if we start from the top, then 40 can only be followed by 95 or 55, 95 can only be followed by 72 or 86 and so on. And I need to find the shortest path from the top to the bottom(from the first row to 100 rows).
I am thinking of plotting a graph from number 1 to 5050(cause there are in total 5050 numbers.) But how can I put weight on it later on? If I calculate weights one by one that will take ages...
Is there an easier way to figure this out?
This is the picture for the first nine rows:

Thank you very much.

Using the first 7 rows of OP's list:
n = 7;
list = {40, 95, 55, 72, 86, 74, 66, 13, 8, 98, 81, 50, 82, 44, 2, 25, 72, 4, 
 21, 7, 15, 53, 39, 39, 31, 97, 86, 61} ;

Column[TakeList[list, Range @ n], Alignment -> Center]


We can use the function layeredGraph (from this answer) to construct a tree with the desired structure.
ClearAll[sa, layeredGraph]
sa = Module[{k = 1, n = #}, SparseArray[Join @@ 
  (Thread[{#, Range[n - # + 1, n + # - 1, 2]}] & /@ Range[n]) :> (k++)]] &;

layeredGraph = Module[{m = sa[#], edges},
    edges = DirectedEdge @@@ DeleteDuplicates[Sort /@ Flatten[Thread /@ 
       ComponentMeasurements[Normal[m], "Neighbors"]]];
    Graph[edges, ##2, VertexCoordinates -> m["NonzeroPositions"]]] &;

Using list as vertex labels and vertex weights:
vweights0 = AssociationThread[Range[(n+1)n/2], list];
g0 = layeredGraph[n, PlotTheme -> "IndexLabeled", ImageSize -> 300];
SetProperty[g0, VertexLabels -> {v_ :> Placed[vweights0[v], Center]}]


We construct a new graph g1 by
(i) adding a source vertex (vertex 0) with vertex weight 0 and sink vertex (vertex n(n+1)/2) with weight 1
(ii) adding new edges connecting the new vertex 0 to vertex 1, and edges connecting the sink vertices of g0 to the new sink vertex (n(n+1)/2).
(iii) For a directed edge a -> b use the vertex weight of b as the edgeweight of the edge a -> b.
vweights = AssociationThread[Range[0, 1 + (n + 1) n/2], 
   Join[{0}, list, {1}]];

newedges = Prepend[Thread[Range[1 + (n - 1) n/2, (n + 1) n/2] ->
    (1 + (n + 1) n/2)], 0 -> 1];
vc = Thread[Range[0, (1 + (n + 1) n/2)] -> 
    Append[Prepend[sa[n]["NonzeroPositions"], {-1, n}], {n + 3, n}]];

g1 = SetProperty[EdgeAdd[g0, newedges], 
    {VertexLabels -> {v_ :> Placed[vweights[v], Center]}, 
     VertexCoordinates -> vc, EdgeWeight -> {e_ :> vweights[e[[2]]]}}];

Finally, we use the  function FindShortestPath to find the shortest path from vertex 0 to vertex 1 + n(n+1)/2 in g1:
shortestpath = FindShortestPath[g1, 0, n (n + 1)/2]


{0, 1, 3, 6, 9, 14, 19, 25, 29}


Total[vweights /@ shortestpath] - 1


273

Row[{g1, HighlightGraph[g1, Subgraph[g1, shortestpath]]}, Spacer[5]]


Another example:
SeedRandom[1]
n = 10;
list = RandomInteger[{1, 100}, (n + 1) n/2];

Column[TakeList[list, Range[n]], Alignment -> Center]


shortestpath =  FindShortestPath[g1, 0, 1 + n (n + 1)/2]


{0, 1, 2, 4, 7, 11, 17, 23, 30, 38, 47, 56} 

Total[vweights /@ shortestpath] - 1


313 

Row[{g1, HighlightGraph[g1, Subgraph[g1, shortestpath]]}, Spacer[5]]


