Page 1 of 2

11153 - Museums

Posted: Sun Dec 31, 2006 8:56 am
by rimu
my dfs (backtracking) solution is getting TLE
what heuristics may i add to cut the run time?

Posted: Sun Dec 31, 2006 10:20 am
by Adrian Kuegel
You should avoid to get into equivalent states more than once. Note that a state consists of visited museums, current location and time used.
But this may still be too slow, since there are up to 68927488 states.
Note that actually you are only interested in the minimum time to reach a certain position having visited some subset of the museums.

Posted: Mon Jan 01, 2007 10:55 am
by Hao Hu
Can you give me some further hint on this problem?
I first thought to use the dynamic programming method that is similar to that in the Hamilton Path which runs in O(2^n*n^2) time but then found one can past a node several times...

my searching + optimization got TLE....

wondering what is the correct method for solving this problem ...

Posted: Mon Jan 01, 2007 3:56 pm
by Adrian Kuegel
Another hint:
Precalculate the fastest routes between any two nodes. You are not interested in how many times you passed a node, just how many times a route stops there, so you can imagine having direct connections corresponding to fastest routes.

Posted: Mon Jan 01, 2007 4:40 pm
by mf
Adrian Kuegel wrote:Note that a state consists of visited museums, current location and time used.
But this may still be too slow, since there are up to 68927488 states.
Actually, just a bitmask of visited museums and current location can be enough. This would be just about 54000 states.
You can use this DP to find minimum time required to visit a subset of museums, and then iterate over all subsets to check their feasibility and pick the one with maximum sum of fun indexes.

Posted: Mon Jan 01, 2007 4:48 pm
by Adrian Kuegel
Yes, that was also my method. I just wanted to show how to optimize his dfs function.

Posted: Mon Jan 01, 2007 9:57 pm
by miras
This trick is often being met on TC events...

Posted: Tue Jan 02, 2007 2:38 am
by coolguy
mf wrote:
Actually, just a bitmask of visited museums and current location can be enough. This would be just about 54000 states.
You can use this DP to find minimum time required to visit a subset of museums, and then iterate over all subsets to check their feasibility and pick the one with maximum sum of fun indexes.
but what about the restriction on the money. how are you gonna handle it ??? please help
BYE

Posted: Tue Jan 02, 2007 3:14 am
by Observer
Dear coolguy:

Please think about that yourself! The point you mentioned is important in getting an acceptable solution for this task. Hint: think how money used is computed.

By the way, we have made several judge solutions for this task. The DP one takes 0.2x seconds. Another acceptable solution is Dijkstra. That solution is longer, has an asymptotically larger time complexity, but is easier to understand. That solution takes about 1 second. The two solutions I wrote above are both in PASCAL.

Posted: Tue Jan 02, 2007 3:15 am
by mf
coolguy wrote:but what about the restriction on the money. how are you gonna handle it ??? please help
As I said, you can actually generate and check every possible subset of museums. Just ignore those subsets, which you can't afford due to time or money contraints.

thank you

Posted: Tue Jan 02, 2007 3:55 am
by coolguy
hey thank you observer and mf.
just after posting in the board i came to understand what wf was trying to say. i got it accepted less than 1 sec. i wasnt understanding how you decreased your states. now i understand :)
thank you once again for letting me know about the idea:)
Bye

Posted: Tue Jan 02, 2007 7:29 am
by rimu
To mf:
how to code using bitmask dp? i googled but found
nothing. can you tell me how it is done or give me
any link from where i can learn it?


To observer:
can you give some hint on the Dijkstra method of
solving this problem?


Thanks.

Posted: Tue Jan 02, 2007 7:41 am
by Observer
About the Dijkstra method:
Adrian Kuegel wrote:Note that actually you are only interested in the minimum time to reach a certain position having visited some subset of the museums.
This hint by Adrian basically describes how we can apply Dijkstra algorithm. :D

Thinking about the order this Dijkstra goes (i.e. what cases are traversed first) will lead you to the DP solution.

Posted: Thu Aug 16, 2007 9:30 am
by rammestain
I got several WA for this problem, :(
please give me some IO

Posted: Wed Aug 29, 2007 8:21 am
by Bert
Ya, can anyone post some tricky test cases?