0% found this document useful (0 votes)
16 views

Problem I

The document describes a number conversion problem where the goal is to convert one positive integer into another positive integer using only the basic arithmetic operations of addition, subtraction, multiplication, and division on two given numbers, while minimizing the total cost based on a provided cost table for each operation. The input provides the starting and target numbers to convert between, the two numbers to use, and the costs for each arithmetic operation. The output is the minimum total cost or "IMPOSSIBLE" if no conversion is possible within the bounds.

Uploaded by

samadnajjar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Problem I

The document describes a number conversion problem where the goal is to convert one positive integer into another positive integer using only the basic arithmetic operations of addition, subtraction, multiplication, and division on two given numbers, while minimizing the total cost based on a provided cost table for each operation. The input provides the starting and target numbers to convert between, the two numbers to use, and the costs for each arithmetic operation. The output is the minimum total cost or "IMPOSSIBLE" if no conversion is possible within the bounds.

Uploaded by

samadnajjar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Problem I: Number Convertor

In this problem, you are given two positive integers, and followed by numbers . Using four basic arithmetic operations (addition, subtraction, multiplication and division(use floor to reach an integer)) and only the given numbers, convert into . For instance suppose and and the numbers are given to you. Two different ways to convert to are as follow: 1. First multiply by , then add to the result for two times. 2. Add to , times. There is just one more point that you should consider; different arithmetic operations have different costs. These costs are represented as a table, in which the cell ( ),( ) ( ) ( ) of this table contains the cost of addition, subtraction, multiplication and division with as a second operand respectively. You should find the minimum cost to convert to such that you never reach a number more than and less than zero.

Input
The number of test cases comes in the first line. For each test case, first there are three integer and . Then you are given positive integer . Finally, in the last lines in each line there are positive integer that represent cost of operations.

Output
For each test case, print the minimum cost to convert to . Sample Input
1 45 768 3 6 2 12 1 2 3 4 1 2 3 4 4 3 2 1 7

to

or IMPOSSIBLE, if we can not convert

Sample Output

You might also like