返回   cpper编程论坛 > 技术杂烩
注册账号 论坛帮助 会员列表 日历事件 搜索 今日新帖 标记版面已读

技术杂烩 找不到地方的技术问题?这里!

回复
 
LinkBack 主题工具 显示模式
  #1 (permalink)  
旧 2004-12-02
yumagi 的头像
高级会员
 
注册日期: 2003-06-09
住址: 上海
帖子: 314
yumagi 正向着好的方向发展
发送 MSN 消息给 yumagi
默认 Bitonic euclidean traveling-salesman problem

The euclidean traveling-salesman problem is the problem of determining the shortest closed tour that connects a given set of n points in the plane. The general problem is NP-complete, and its solution is therefore believed to require more than polynomial time.


J. L. Bentley has suggested taht we simplify the problem by restricting our attention to bitnoic tours, that is, tours that start at the leftmost point, go strictly left to right to the rightmost point, and then go strictly right to left back to the starting point. In this case, a polynomial-time algorithm is possible.

Desrcibe an O(n^2)-time algorithm for determining an optimal bitonic tour. You may assume that no two points have the same x-coordinate. (Hint: Scan left to right, maintaining optimal possibilities for the two parts of the tour.)
__________________

我庄严地宣誓
我将用真诚的良心承担如下的许诺和保证:
我将勇敢地去捍卫真正的科学
将其开拓,为之添彩
既不为厚禄所驱,亦不为虚名所赶
只求上帝真理的神辉普照大地、发扬光大
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #2 (permalink)  
旧 2004-12-02
yumagi 的头像
高级会员
 
注册日期: 2003-06-09
住址: 上海
帖子: 314
yumagi 正向着好的方向发展
发送 MSN 消息给 yumagi
默认

上面那道题目完全摘录自CLRS的Problem, 15-1, 我想了一下,觉得很难定义出一个optimal structure, 它说从左到右扫描,好像没有办法说第i到第j个点的最优解是XXXXX,大家有什么想法吗?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #3 (permalink)  
旧 2004-12-03
Elminster 的头像
超级版主
 
注册日期: 2002-09-09
帖子: 1,764
Elminster 正向着好的方向发展
默认

别着急,慢慢想。不瞒你说,去年我自己做这道题的时候,想了大约一个下午加一整个晚上,第二天起来把想法整理清楚写出来,又花了一个上午。下周二当朱老师在课上说“将来考试题目和这道题差不多难”的之后,来上课的人一下子少了三分之一 ……
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #4 (permalink)  
旧 2004-12-03
cat cat 当前离线
高级会员
 
注册日期: 2003-11-06
帖子: 1,563
文章: 6
cat 正向着好的方向发展
默认

上课忍不住,做了两节课。下次上课前有得自己看书了

下面是一些想法:
代码:
由于x坐标不同,设为x0, x1, x2, ..., xn,则可以用0, 1, 2, ..., n来表示这些点。 构造一个distance表d[i, j] = distance(i, j) (i < j) 设有正向路径a0 = 0 < a1 < a2 ... < ai = p 从0点顺序到达p点, 有回程路径bj = q > b(j-1) ... > b0 = 0 从q点顺序到回到0点,两路径覆盖了0..p中的所有的点。 且p > q. 令w(p, q)为所有这些路径中路程最小的路径的路程。 则由定义, w(p, q) = min{sum(k = 0 to i-1){d[a(k), a(k+1)]} + sum(k = 0 to j-1){d[b(k), b(k+1)]}} = min{ sum(k = 0 to i-2){d[a(k), a(k+1)]} + sum(k = 0 to j-2){d[b(k), b(k+1)]} + d[a(i-1), p] + d[b(j-1), q] } 由于0..p均必须包含在路径中,所以p-1必定包含在某路径中, 由于单调性,当q != p-1时,必有a(i-1) = p-1,否则,有q = p-1. 1.当q < p-1时, w(p, q) = min{ sum(k = 0 to i-2){d[a(k), a(k+1)]} + sum(k = 0 to j-2){d[b(k), b(k+1)]} + d[p-1, p] + d[b(j-1), q] } = d[p-1, p] + min(b(j-1) = 0 to q-1){w(p-1, b(j-1)) + d[b(j-1), q]} 注:以上将两个sum换成w基于以下(至少我认为是)事实:min{a + b} = min{ min{a} + b },其中a, b 为某集合,a+b表示其中元素任意相加后的集合。(这条如果错了,以上一下全是胡扯 :P ) 2.当q = p-1时, w(p, q) = min{ sum(k = 0 to i-2){d[a(k), a(k+1)]} + sum(k = 0 to j-2){d[b(k), b(k+1)]} + d[a(i-1), p] + d[b(j-1), p-1] } = min{ sum(k = 0 to i-2){d[a(k), a(k+1)]} + sum(k = 0 to j-1){d[b(k), b(k+1)] + d[a(i-1), p] } 观察前面的两个sum,由于b(j) = p-1 有 a(i-1) != p, 又 a(i-1) < p, 故a(i-1) < p-1. 交换路径a和b, 这个sum就变成了w(p-1, a(i-1)). 于是,有 w(p, q) = min(a(i-1) = 0 to p-2){w(p-1, a(i-1)) + d[a(i-1), p]} 最后,设正向路径a: a0 = 0 < a1 < a2 ... < ap = n, 逆向路径b: bq = n > b(q-1) ... > b0 = 0, 则要求的最短路程为: w = min{sum(k = 0 to p-2){d[a(k), a(k+1)]} + sum(k = 0 to q-2){d[b(k), b(k+1)]} + d[a(p-1), n] + d[b(q-1), n] } 由于路径a, b分别从0到n和从n到0, 故交换路径a和b不会对上述min中的值产生影响。 因此,不妨设经过点n-1的路径为a,则a(p-1) = n-1,于是 w = min{sum(k = 0 to p-2){d[a(k), a(k+1)]} + sum(k = 0 to q-2){d[b(k), b(k+1)]} + d[n-1, n] + d[b(q-1), n] } = d[n-1, n] + min{sum(k = 0 to p-2){d[a(k), a(k+1)]} + sum(k = 0 to q-2){d[b(k), b(k+1)]} + d[b(q-1), n]} = d[n-1, n] + min(b(q-1) = 0 to n-2){ w(n-1, b(q-1)) + d[b(q-1), n] } 总结一下: w(1, 0) = d[1, 0]; w(p, q) = (q < p-1) -> d[p-1, p] + min(b(j-1) = 0 to q-1){w(p-1, b(j-1)) + d[b(j-1), q]}; (q = p-1) -> min(a(i-1) = 0 to p-2){w(p-1, a(i-1)) + d[a(i-1), p]}; w = d[n-1, n] + min(b(q-1) = 0 to n-2){ w(n-1, b(q-1)) + d[b(q-1), n] } 由于构造w(p, q)需要知道w(p-1, j) where 0 <= j < p-1, 所以指定构造顺序为: for (p = 1 to n-1) for (q = 0 to p-1) compute w(p, q); compute w; 复杂度: sum(p = 1 to n-1){ sum(q = 0 to p-1) {q} } = n(n-1)^2 / 6 = O(n^3)
不过复杂度是O(n^3)的,且不知对错

这东西感觉有点像optimal bst,那个算法最初也是O(n^3),
好像是因为w(p, q)里面那个min闹鬼,于是就变成O(n^2)了。
怎么闹的我还没看过,不太清楚,所以这里也没法借鉴了。
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #5 (permalink)  
旧 2004-12-03
cat cat 当前离线
高级会员
 
注册日期: 2003-11-06
帖子: 1,563
文章: 6
cat 正向着好的方向发展
默认

sigh, 这东西这么写看着好累。
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #6 (permalink)  
旧 2004-12-03
初级会员
 
注册日期: 2004-11-22
帖子: 23
Bird- 正向着好的方向发展
默认

这题不是可以DP吗?某届中学生IOI里就有完全相同的一题。
让D(i, j) denote the shortest tour from i to N and back to j (1,2,...N being the vertices with increasing X co-ordinates).
Hence we have D(i,j) = max { D(i+1,j) + distance[i,i+1], D(i,j+1) + distance[j,j+1] } (大致是这样,还要判断i=j+1和j=i+1时的特殊情形,因为D(i,i)或D(j,j)中一个顶点被用了2次), 所以O(N^2).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
  #7 (permalink)  
旧 2004-12-04
cat cat 当前离线
高级会员
 
注册日期: 2003-11-06
帖子: 1,563
文章: 6
cat 正向着好的方向发展
默认

果然在同样的地方闹鬼了。原来只要2选1就行了。以后找找原因看。
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
回复时引用此帖
回复

书签

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码
Trackbacks are 启用
Pingbacks are 启用
Refbacks are 启用



所有时间均为格林尼治时间 +9。现在的时间是 07:22 AM


Powered by vBulletin® 版本 3.7.0
版权所有 ©2000 - 2009,Jelsoft Enterprises Ltd.
(C) Copy Right All Right Reserved 2001 - 2007

Search Engine Friendly URLs by vBSEO 3.1.0