This page is still under construction.

Parts of this page are still being built. What you see may change.

Wi-Fi Towers (Small)

Interview

Time limit5sMemory limit512 MB

Summary
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 nn 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 TT runs protocol B, then every tower inside the range of TT must run protocol B as well, so that it can read the data TT 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 00.

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, TT. Each test case starts with a line holding the number of towers, nn. Each of the next nn lines contains four integers xx, yy, rr, ss, describing a tower at coordinates (x,y)(x, y) with range rr and score ss for upgrading it to protocol B.

Constraints:

  • 1≤T≤551 \le T \le 55
  • 1≤n≤151 \le n \le 15
  • −10000≤x,y≤10000-10000 \le x, y \le 10000
  • 1≤r≤200001 \le r \le 20000
  • −1000≤s≤1000-1000 \le s \le 1000
  • No two towers share the same coordinates.

Output

For each test case, print one line:

Case #X: score

XX is the number of the test case, starting from 1, and score is the largest total score you can reach.

Examples3

  1. Example 1

    Input
    1
    5
    0 1 7 10
    0 -1 7 10
    5 0 1 -15
    10 0 6 10
    15 1 2 -20
    
    Expected output
    Case #1: 5
    
  2. Example 2

    Input
    2
    1
    0 0 1 5
    1
    0 0 20000 -7
    
    Expected output
    Case #1: 5
    Case #2: 0
    
  3. Example 3

    Input
    2
    3
    0 0 10 8
    10 0 10 -3
    20 0 1 -2
    3
    0 0 10 8
    10 0 10 -5
    20 0 1 -5
    
    Expected output
    Case #1: 3
    Case #2: 0