【发布时间】:2015-06-20 17:20:45
【问题描述】:
我正在尝试解决spoj 上的COURIER 问题。我能够理解我必须使用动态编程方法来解决 TSP,但我无法完全理解我在同一对城市之间处理多个包裹的方法是否正确。我的伪代码如下:
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 个这样不同的请求的信息。我知道我可以解决这个问题并且知道,但我想先获得一些解决方案的建议。
【问题讨论】:
标签: algorithm language-agnostic dynamic-programming