我正试图解决关于spoj的COURIER问题。我能够理解,我必须用动态规划方法解决TSP问题,但我无法准确理解我在同一对城市之间处理多个包裹的方法是否正确。我的伪代码将有所如下:什么是SPOJ COURIER的正确方法
1) Use floyd warshall to find all pair shortest path in O(n^3). Some pair of cities are connected by more than one roads, I can just keep the shortest one for my undirected graph.
2) Add the shortest cost for each request start to end.
3) Create a new directed graph for each of 12 requests and homecity. The node of this new graph will be a merge of each request's source and destination. The edge weight between a->b can be calculated by shortest path between 'a' request's destination to 'b' request's source.I am thinking of duplicating the pairs if I have multiple request between them.
4) Use a TSP DP to solve this new undirected 13 city TSP problem. O(n^2 2^n) would come around 1384448. Not sure whether this will time out for multiple test cases.
能否请您给您的输入,我在这个问题与我建立这个新的有向图的方法复杂化?我没有使用只有5个这样的不同请求的信息。我知道我可以把它弄清楚,但我想先解决一些解决方案。
非常感谢您的回答。我仍然无法知道如何让TSP多次访问多个城市进行多次交付?您可以添加一个小的pseuodcode或只是更多的描述。这将是很大的帮助。 – Naman
不需要感谢我:)只要upvote和接受,如果你喜欢我的回答:)将作出一个简短的编辑如何接近它,并让你休息给你 – Riko