This page is still under construction.

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

European railroad tracks

Time limit1sMemory limit128 MB

Summary
Given up to 8 distinct gauge lengths, find the smallest number of points on a line such that every gauge appears as a distance between two points.
Level

Medium6 of 10

Topics
Brute force, Backtracking, Math
Solved
No attempts yet

Problem

Different countries in Europe use different railroad systems. Not only do their trains run on different voltages, but the distance between the two rails (the gauge) also varies from country to country. The table below lists some of the railway gauges actually in use.

Broad gauge (Spain)1674 mm
Broad gauge (Portugal)1665 mm
Broad gauge (Ireland)1600 mm
Broad gauge (Finland)1524 mm
Broad gauge (former USSR)1520 mm
Standard gauge1435 mm
Narrow gauge (metre)1000 mm

A museum exhibits trains from several countries. To show visitors the trains sitting on a track, it needs a suitable gauge for every train. Because only one train is displayed at a time, a single rail may be shared by trains of different types. Hence, for nn trains that each require a different gauge, n+1n + 1 rails are always enough (every train uses the leftmost rail together with the rail that lies exactly its required gauge away). Sometimes, however, even fewer rails suffice.

The rails are placed at distinct positions along one straight line, and a train may use any two rails whose spacing is exactly equal to its required gauge. Given the required gauges, determine the minimum number of rails needed to build a track that every train can use.

Input

The first line contains the number of test cases. Each test case begins with a line containing nn, the number of distinct required gauges. The next line contains nn integers between 10001000 and 50005000, each giving one required gauge.

You may assume 1≤n≤81 \le n \le 8. Moreover, every test case in the input is guaranteed to be solvable with at most 55 rails.

Output

For each test case, print two lines. The first line has the form Scenario #X, where X is the test case number starting from 11. The second line contains the minimum number of rails needed to build a track usable by every train.

Print one blank line between the outputs of two consecutive test cases.

Examples3

  1. Example 1

    Input
    3
    4
    1524 1520 1609 1435
    3
    1000 1520 1600
    6
    1000 2000 3000 4000 1500 2500
    
    Expected output
    Scenario #1
    4
    
    Scenario #2
    4
    
    Scenario #3
    5
    
  2. Example 2

    Input
    1
    1
    2000
    
    Expected output
    Scenario #1
    2
    
  3. Example 3

    Input
    1
    2
    1000 2000
    
    Expected output
    Scenario #1
    3