htenneK's blog

By htenneK, history, 3 years ago, In English

This is part of a problem from Shopee Code League 2021. Essentially, I need to DP starting from the center hexagon(Hexagon 1) to other shapes. The transition from a hexagon would be to shapes that are adjacent(e.g. Hexagon 1 transitions to 2,3,4,5,6,7). A pentagon would have 5 transitions(e.g. Pentagon 7 would have transitions to 1,2,6,8,16).

I cannot think of how to do this DP transition with arrays. My solution was to convert every hexagon and pentagon to a node, then construct undirected edges between them and their adjacent nodes, and finally DP on the graph.

Is there any other way to do this?

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
3 years ago, # |
  Vote: I like it +5 Vote: I do not like it

I think your solution, just building (hardcoding?) a graph is the best you can do.

Trying to use some sort of clever indexing is not worth it here IMO. You'd end up with messy formulas and special cases that will inevitably fail.