Let's say we have n disjoint horizontal parallel bars. Then we need to connect each pair of bars with a vertical line, so there are total sum(n,...,1) lines. If any of these connections between two bars crossed other bars p times, then we say the cost is p. The question is to find the minimum total cost for n bars.
n=1, p=0: n=2, p=0: n=3, p=0 n=4, p=0:
--- -----
| | | | |
--- --- --- | --- | |
| | | | | | |
--- --- | --- |
| | |
-------
n=6, p=3:
-------------
| | | | |
| ----- | | |
| | | | | | |
| | | --- | |
| | | | | | |
--*-*-- | | |
| | | | |
| ----*-- |
| | | |
-----------
n=7, p=6:
---------------
| | | | | |
| --*---- | | |
| | | | | | | |
| | | --*-- | |
| | | | | | | |
| | --- | | | |
| | | | | | | |
| | | --*-*-- |
| | | | | | |
--*-*---- | |
| | | |
-------------
n=8, p=11
-------------------
| | | | | | |
| --1-1------ | | |
| | | | | | | |
| | --2---- | | | |
| | | | | | | | | |
| | | | | --1-- | |
| | | | | | | | | |
| | | --1-- | | | |
| | | | | | | | |
| | | | ----1-1-- |
| | | | | | | |
--1-1-1------ | |
| | | | |
-----------------
Any hints of how to find the patterns or logic behind it will be great.