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

Автор ayushrocker92, 9 лет назад, По-английски

How can i solve this problem

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

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

To solve this problem we should use dynamic programming; States will be [last vertex][mask for vertexes];

At every moment we will pick vertex which connected to our last vertex;

And if last vertex is already connected with starting vertex and if we already have at least 3 vertexes in our mask, we should add 1 to answer of this state;

Answer of current state will be d[next vertex][mask + next vertex]

Answer will be d[starting vertex][mask + starting vertex]

Here is my code for better understanding