Seeking the smallest ring

method one

  Violence to solve:

  Deleting a i, j, between the edges, and then seek i, j, between the shortest;

  Constantly deleting the enumeration side and i, j, two points until you find the correct answer;

  Time complexity 0 (n ^ 4)

Method Two

  Seeking the smallest ring Floyed

  for (k =. 1; k <= n-; k ++)
  {
    for (I =. 1; I <k; I ++) // Let k be the highest-numbered ring point
      for (j = i + 1; j <K; J ++)
        ANS = min (ANS, DIS [I] [J] + E [I] [K] + E [K] [J]); // find the shortest loop length
    for (i = 1 ; I <= n-; I ++)
      for (J =. 1; J <= n-; J ++)
        DIS [I] [J] = min (DIS [I] [J], DIS [I] [K] + dis [k] [j] ); // ans update sequence can not be changed with a repetitive dis take one side or inevitable
   }

  Time complexity 0 (n ^ 3)

Guess you like

Origin www.cnblogs.com/wjj226316/p/11617439.html