Explosive Wiring
Time limit2sMemory limit512 MB
Pick a set of polyline wires so that each chosen wire touches exactly one other chosen wire, maximizing the total usefulness of the set.
- Level
Medium7 of 10
- Topics
- Geometry, Graph, Dynamic programming
- Solved
- No attempts yet
Problem
You are designing the wiring for a new kind of computer chip. Unfortunately, the wires are made of a strange material that explodes under the wrong conditions. You have a set of wires that you can install on the chip, and each wire has a usefulness value.
Assume the chip lies on the x-axis. Each wire connects two different points on the x-axis and is described by a 2D polyline that connects those two points. A polyline is a sequence of points joined by straight line segments. All wires lie above the x-axis except where they touch the chip at their first and last points. In addition, all x-coordinates of each wire's polyline stay within the interval formed by that polyline's first and last points.

Two wires interfere if their polylines touch or intersect at one or more points. A wire does not interfere with itself. A set of wires is safe if every wire in the set interferes with exactly one other wire in the set. The utility of a set is the sum of its wires' usefulness values. Given a set of wires to choose from, find the largest utility over all safe subsets.
Input
The first line contains a single integer (1 ≤ ≤ 150), the number of wires.
Each of the next lines describes one wire. A line starts with two integers (0 ≤ ≤ 100 000), the usefulness of the wire, and (3 ≤ ≤ 10), the number of points in the polyline. Then come pairs of integers (0 ≤ , ≤ 100 000), which define the polyline --...-.
It is guaranteed that and for . Also, and for . All points in the input are distinct.
Output
Print the largest utility over all safe subsets of the given wires.