This page is still under construction.

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

Pimp My Ride

Time limit1sMemory limit128 MB

Summary
Given n jobs with base prices and pairwise surcharges paid when a later job follows an earlier one, find the cheapest order to finish all jobs.
Level

Medium6 of 10

Topics
Dynamic programming, Bit manipulation
Solved
No attempts yet

Problem

There are plenty of cars, motorcycles, trucks, and other vehicles on the streets that badly need refurbishment. You have taken on the job of restoring them, funded by a generous budget from a major TV station.

There is a lot of work to do, so you decide to hand off the individual tasks — painting, interior decoration, and so on — to specialized garages. Because each garage handles only certain kinds of work, different tasks go to different garages. Worse, a garage tends to charge more when the car already looks good: a painter, for example, may charge extra for a car whose interior is already all leather. Since these surcharges depend on which jobs have already been completed, you want to save money by finding an optimal order in which to perform the jobs.

The jobs are numbered 11 through nn. Each job ii has a base price, and for every ordered pair of jobs (i,j)(i, j) with i≠ji \ne j there is a surcharge sijs_{ij} (in US dollars): you must pay an additional sijs_{ij} for job ii if and only if job jj was completed before job ii. The total cost of a job order is the sum, over all jobs, of each job's base price plus the surcharges owed for the jobs already finished at the moment it is performed. Compute the minimum possible total cost to finish all jobs.

Input

The first line contains the number of scenarios.

Each scenario starts with a line containing the number of jobs nn (1≤n≤141 \le n \le 14). The next nn lines describe the cost matrix, each containing exactly nn integers. On line ii (for 1≤i≤n1 \le i \le n), the ii-th integer is the base price of job ii, and the jj-th integer (for j≠ij \ne i) is the surcharge for job ii that applies if job jj was completed before it. Every price and surcharge is a non-negative integer not exceeding 100000100000.

Output

For each scenario, first print a line:

Scenario #i:

where ii is the scenario number, counting from 11. Then print a line:

You have officially been pimped for only $p

where pp is the minimum total cost. Print a blank line between consecutive scenarios.

Examples4

  1. Example 1

    Input
    2
    2
    10 10
    9000 10
    3
    14 23 0
    0 14 0
    1000 9500 14
    
    Expected output
    Scenario #1:
    You have officially been pimped for only $30
    
    Scenario #2:
    You have officially been pimped for only $42
    
  2. Example 2

    Input
    1
    1
    42
    
    Expected output
    Scenario #1:
    You have officially been pimped for only $42
    
  3. Example 3

    Input
    1
    2
    5 0
    0 7
    
    Expected output
    Scenario #1:
    You have officially been pimped for only $12
    
  4. Example 4

    Input
    3
    1
    5
    1
    10
    2
    1 1
    1 1
    
    Expected output
    Scenario #1:
    You have officially been pimped for only $5
    
    Scenario #2:
    You have officially been pimped for only $10
    
    Scenario #3:
    You have officially been pimped for only $3