1204 - Fun Game

All about problems in Volume 12. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
flashion
New poster
Posts: 17
Joined: Thu Jul 24, 2014 10:29 pm

1204 - Fun Game

Post by flashion »

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?
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 1204 - Fun game

Post by brianfry713 »

Code it and see if it works.
Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 12 (1200-1299)”