我正試圖解決關於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