시간 제한
메모리 제한
시간 제한
1초
메모리 제한
128 MB
The Countdown TV show has a part that consists of obtaining a number by combining six dierent numbers using the basic mathematical operations: addition, subtraction, product and division. The basic rules for the game are:
Example:
Your task is to write a program that calculates the best sequence of operations that lead to the target number T. If there is no way to get T, give the closest solution.
The input consists of several cases, one per line. The rst line indicates the number of cases C to process (1 ≤ C ≤ 50). Each of the following C lines contains six natural numbers from the set {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 25, 50, 75, 100} and another natural number T (1 ≤ T ≤ 999) that indicates the target.
The output for each case will be a set of lines with the following format:
If there is more than one best approximation, all of them will be considered valid. The sequence of operations should be valid, you should never use a value before you obtain it. It is OK to print more operations than needed as long as they are valid. Note that all the numbers and operators must be separated by at least one space.