Блог пользователя uzumaki_naruto_

Автор uzumaki_naruto_, история, 6 лет назад, По-английски

Graph has 10 vertices.

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
6 лет назад, # |
Rev. 3   Проголосовать: нравится +4 Проголосовать: не нравится

Obviously we will have a certain number of eulerian paths between only one pair of vertices, as the degrees of the end vertices should be odd and all other degrees should be even. The problem now becomes to find the number of eulerian paths between fixed 2 vertices. Now let's add an edge between these two vertices. Well now the problem becomes to find the number of eulerian circuits in this new graph. Well it appears that the number of eulerian circuits as a problem is considered #P-complete, which means it still hasn't been solved. Are you sure your problem is that, or you missunderstood it?

  • »
    »
    6 лет назад, # ^ |
    Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

    I completely misunderstood the problem, We are given a graph of 10 vertices and we have to find number of "Hamiltonian" paths between any 2 vertices given by a matrix d[11][11]. What i think can be done is generate all permutations of [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and check if it is a valid path and if it is a valid path, increment d[first vertex][last vertex] but this approach times out. DFS also times out because the number of edges are huge. Edited the blog post

    • »
      »
      »
      6 лет назад, # ^ |
        Проголосовать: нравится +3 Проголосовать: не нравится

      Well this approach is too slow. To solve the problem we first will fix the end vertices.

      Now consider the following dp:

      DP[first vertex][current vertex][visited vertices] = number of ways to reach this state from (first vertex, first vertex, only the first vertex is visited), were "visited vertices" is a bitmask of the visited vertices.

      Then the answer for a query (x, y) — x is the first vertex and y is the last one — is DP[x][y][ 2N - 1 ].

      The complexity will be which should be fast enough when N ≤ 10.

»
6 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

If you use a variation of traveling salesman you should be able to solve it in 2^N*N^3 You have dp[i][j][mask], where it means that you start in node i, want to end in node j and the 1s in the mask tell you which nodes you can visit.