电路板问题
来源:互联网 发布:豆瓣怎么做淘宝 编辑:程序博客网 时间:2024/05/17 09:24
There are n terminals on each side of a circuit board indexed with 1, 2, …, n from left to right, as shown in the following figure. We need to connect terminal i (1 ≤ i ≤ n) on the top side with a unique terminal π(i) on the bottom side, and vice versa. In other words, we need n lines (i, π(i)) (1 ≤ i ≤ n) to connect n pairs of terminals,.
Two lines (i, π(i)) and (j, π(j)) ( i ¹ j) will cross each other if i < j but π(i) > π(j), or vice versa. Two lines are called compatible if they do not cross each other. We wish to find the largest set of mutually compatible lines so that they can be layout on the same layer of circuit without crossing each other.
Please model this problem as a graph problem first and then design an O(n2) algorithm to solve it.
Solution:
We construct a directed graph G(V, E) as follows.
(1) For each line (i, π(i)) (1 ≤ i ≤ n), we construct a vertex vi.
(2) If lines (i, π(i)) and (j, π(j)) ( i < j) are compatible, then draw an edge from vi to vj.
(3) Add one vertex s to V, so V = {s} È { v1, v2, v3, ...., vn }.
(4) Draw an edge from s to each vi (1 ≤ i ≤ n).
It is easy to see that lines with indices i1 < i2 < i3 < .... < vk are mutually compatible if and only if there is a path <s, v1, v2, v3, ...., vk>. Therefore, the longest path in G corresponds to the largest compatible set. We can use the algorithm in problem 3 to find the longest path in G.
The time complexity is O(n2) because we may check every pair of lines when we construct the graph G. Finding the longest path needs O(n+m) = O(n2) time in the worst case.
- 电路板问题
- 电路板排列问题
- 电路板排列问题
- 电路板排列问题
- 最小长度电路板排列问题
- 最小长度电路板排列问题
- 最小长度电路板排列问题
- 画电路板中遇到的问题
- 画电路板应注意的问题
- 印刷电路板设计及其相关问题介绍
- 最小长度电路板排列问题一
- 最小长度电路板排列问题二
- 最小长度电路板排列问题(回溯)
- 发一个迷宫问题(又称电路板问题)的源码
- 最小长度电路板排列问题 5_2 6_1
- 不同模块的电路板之间的共地问题
- 算法java实现--回溯法--电路板排线问题--排列树
- 算法java实现--分支限界法--电路板排线问题
- BCB消息拦截
- Linux修改网关
- 汉字转拼音类
- IDirect3DDevice9::SetTexture 方法
- 汉字转拼音类
- 电路板问题
- 回溯算法
- 详细解说 STL 排序(Sort)
- 实验三 贪心算法的应用
- 部署网站技巧
- C# this学习
- DateTime类型[C#]
- MFC库文件版本对程序的影响:Unhandled exception in ***.exe(MFCO42D.dll)0xC00000005:Access Violation,但多数情况下还是对内存操作不当造成的
- 防止用户通过地址栏直接访问主页