Problem G
Quantum
At the Institution for Bits and Bytes at University of Ramville, Prof. Jeremy Longword and his eight graduate students are investigating a brand new way of storing and manipulating data on magnetic disks for use in hard drives. The method is based on letting quasimagnetic quantum operations operate on the sectors on the disk, and is, of course, safer and more reliable than any earlier invented storage method. The use of each quantum operation costs a certain amount of energy, and the more energy the storage unit consumes, the warmer it will get. Therefore, you and your research team, are assigned the task of writing a program that, given sets of possible quantum operations and their costs, can calculate the lowest possible total cost for transforming a set of data to the wanted result.
On the disk, binary words of length
Input
The input starts with a single positive integer
-
One line containing three integers:
, and separated by one space. -
indicates the length of the binary words and the quantum operations. -
is the number of quantum operations that are available for use when transforming the binary words. -
is the number of binary words that are to be transformed in the current test case.
After this,
Finally, there are
Output
Each test case should produce a row containing a list of the energy costs of transforming each of the binary words. The costs should be separated by a single space and presented in the same order as the corresponding input. When there is no successful way of transforming a binary word, “NP” (meaning not possible) should be printed instead.
Sample Input 1 | Sample Output 1 |
---|---|
2 4 3 3 NFFN 1 NFNF 2 NNFN 4 0010 0100 0001 0010 0100 1000 4 4 5 CFSF 4 NNSS 3 FFFF 5 FNFN 6 1111 0000 1001 0110 0101 1000 1000 0011 0000 1001 |
1 3 NP 5 4 8 9 9 |