Wi-Fi Towers (Small)
InterviewTime limit5sMemory limit512 MB
Choose which towers to upgrade to protocol B so the total score is maximized, where upgrading a tower forces every tower in its range to be upgraded too.
- Level
Medium4 of 10
- Topics
- Graph, Brute force, Backtracking
- Solved
- No attempts yet
Problem
A wireless network has towers. Every tower has a range, and it can send data to another tower when the distance between the two towers is at most the range of the sending tower.
All towers currently run the old protocol A. A new protocol B gives better bandwidth, so you plan to upgrade some towers to protocol B.
One restriction applies. If tower runs protocol B, then every tower inside the range of must run protocol B as well, so that it can read the data sends. The other direction is free: a tower running protocol B can still receive data from a tower running protocol A.
An upgrade brings a benefit and also costs something to install, so every tower carries a score that may be positive or negative. Pick the set of towers to upgrade so that the sum of the scores of the upgraded towers is as large as possible. Upgrading no tower at all is a valid choice, and its total is .
Distances are Euclidean. A tower always lies inside its own range, so that part of the restriction never blocks a choice.
Input
The first line contains the number of test cases, . Each test case starts with a line holding the number of towers, . Each of the next lines contains four integers , , , , describing a tower at coordinates with range and score for upgrading it to protocol B.
Constraints:
- No two towers share the same coordinates.
Output
For each test case, print one line:
Case #X: score
is the number of the test case, starting from 1, and score is the largest total score you can reach.