Hello guys,
I've been thinking about this problem lately and I came up with some solution. I wanna share it with you and ask you to tell me if it makes sense.
1) I grab the longest paper and check if it contains all of children by checking if other papers are substring of it (with cycle).
2) If yes, I print solution.
3) If not, I remove all papers that are substrings of other papers (they don't contain any information for solution)
4) I create a graph G(V,E) where v c V are papers and cost of the edge: (v1, v2) c E is: length(v2) - longest prefix-suffix of string: "v2#v1", that means how much letter i need to add to v1 string to get v1v2 string.
5) On this graph I run TSP algorithm in O(2^n * n^2) which seems feasible.
6) The solution is the shortest path found by algorithm.
What do you think?
1204 - Fun Game
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 1204 - Fun game
Code it and see if it works.
Check input and AC output for thousands of problems on uDebug!