algorithm - What can be a correct approach for SPOJ COURIER -


i trying solve courier problem on spoj. able understand have solve tsp dynamic programming approach unable understand whether approach handling multiple parcel between same pair of cities correct or not. pseudocode following:

1) use floyd warshall find pair shortest path in o(n^3). pair of cities connected more 1 roads, can keep shortest 1 undirected graph. 2) add shortest cost each request start end. 3) create new directed graph each of 12 requests , homecity. node of new graph merge of each request's source , destination. edge weight between a->b can calculated shortest path between 'a' request's destination 'b' request's source.i thinking of duplicating pairs if have multiple request between them. 4) use tsp dp solve new undirected 13 city tsp problem. o(n^2 2^n) come around 1384448. not sure whether time out multiple test cases. 

can please give inputs complicating problem approach of creating new directed graph? not using information there 5 such different requests. know can coed , know want suggestions on solution first.

nice problem.

after doing point 1), can ignore cities not source or address of delivery.

therefore have 10 cities traveler , 2^12 possible combinations of tasks still complete.

you can dp 2 arguments: current city , deliveries complete, can store bit mask.

edit:

as mentioned have 2 arguments: p tracks current position , mask tracks visits have done.

mask works bit mask: http://en.wikipedia.org/wiki/mask_%28computing%29

you start mask 0, in binary 000000000000. when example 5th requested travel change mask to: 000000010000 etc.

you start calling f(p=0, mask=0).

when solving f(p, mask) have 2 options. can move other city p2. can make travel p -> p2 if 1 of travels haven't done. out of these options have choose best one.

this problem quite tricky , suggest first solving easier problems using bit-masks begin with. can find here: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&itemid=8&category=778


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -