Choose the largest subset of at most 16 coins and an order of moves so no moving coin ever collides with a stationary or already-moved coin.
Hard8GeometryBit manipulationDynamic programmingGreedyNo attempts yetTime limit2sMemory limit512 MBYou are playing a coin puzzle. The rules are as follows.
There are N coins on a table. The i-th coin is a circle of radius ri, and its center is initially at (sxi,syi). Each coin also has a target position: you have to move the i-th coin so that its center is at (txi,tyi). You move coins one at a time, and you can move each coin at most once. When you move a coin, it travels from its initial position to its target position along a straight line. In addition, coins must never collide with each other, including in the middle of a move.
The score of the puzzle is the number of coins you move from their initial positions to their target positions. Write a program that determines the maximum score for the given puzzle.
The input consists of a single test case in the following format.
N
r1 sx1 sy1 tx1 ty1
.
.
.
rN sxN syN txN tyN
The first line contains an integer N (1≤N≤16), the number of coins in the puzzle. The i-th of the following N lines contains five integers ri, sxi, syi, txi, and tyi (1≤ri≤1,000, −1,000≤sxi,syi,txi,tyi≤1,000, (sxi,syi)=(txi,tyi)). ri is the radius of the i-th coin, (sxi,syi) is its initial position, and (txi,tyi) is its target position.
At their initial positions, no two coins touch or overlap. You can also assume that the maximum score does not change even if the radius of every coin changes by 10−5.
Print the maximum score of the given puzzle on a single line.
In the first example, the third coin cannot move because the other two coins are in its way.

Example 1. Initial positions

Example 1. After the moves