eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Mass Production

Mass Production

Star Fleet needs to deploy a squadron of ships at the edge of Federation space. There is a nearby planet where the ships can be built, but the planet doesn't have the infrastructure to support the construction of ships from scratch. It is, however, possible to assemble the ships using prefabricated kits containing an assortment of base parts. Each kit is designed to be turned into a ship by converting the base parts into the necessary ship components. To ensure consistent construction, parts from di erent kits should not be mixed and matched; each kit must be used in its entirety to construct exactly one ship. This squadron consists of two distinct classes of ships, Class A ships and Class B ships. Both classes consist of the same total number of components, though their individual makeup is di erent. Each base part is capable of being turned into any type of ship component, though the cost to turn a base part into a ship component varies depending on the base part type and the ship component type. You are responsible for creating these prefabricated kits, which must all be identical to each other. You have access to M5, the greatest computer of all time. What should the composition of the kit be to minimize the total cost of constructing the squadron? \InputFile Input begins with a line with one integer \textbf{T} (\textbf{1} ≤ \textbf{T} ≤ \textbf{50}) denoting the number of test cases. Each test case begins with a line with four integers \textbf{M}, \textbf{N}, \textbf{A}, and \textbf{B} (\textbf{1} ≤ \textbf{M}, \textbf{N} ≤ \textbf{10}, \textbf{1} ≤ \textbf{A}, \textbf{B} ≤ \textbf{100}), where \textbf{M} denotes the number of types of base parts, \textbf{N} denotes the number of types of ship components, \textbf{A} denotes the number of Class A ships required, and \textbf{B} denotes the number of Class B ships required. Next is a line with \textbf{N} integers \textbf{a_i} denoting the quantity of ship component \textbf{i} needed for each Class A ship (\textbf{0} ≤ \textbf{a_i} ≤ 100). Next is a line with \textbf{N} integers \textbf{b_i} denoting the quantity of ship component \textbf{i} needed for each Class B ship (\textbf{0} ≤ \textbf{b_i} ≤ \textbf{100}, \textbf{Σ_ia_i = Σ_ib_i}). Next follow \textbf{M} lines with \textbf{N} integers \textbf{c_ij} (\textbf{0} ≤\textbf{c_ij} ≤ \textbf{100}) denoting the cost of converting a single base part \textbf{i} into a single ship component \textbf{j}. \OutputFile For each test case, output a line with a single integer equal to the minimum total conversion cost of assembling all the ships from the factory kits. \Note In the sample given, the optimal factory kit has one of each base part; such a kit costs \textbf{1} to convert into the components for a Class A ship and \textbf{2} to convert into the components for a Class B ship.
Ліміт часу 5 секунд
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
1
3 2 4 5
2 1
1 2
0 4
1 2
4 0
Вихідні дані #1
14
Джерело 2013 Pacific Northwest Region Programming Contest