Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|

Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |

Language: Chemical Weighing
Description Facer is the chemical keeper in a laboratory. Every day he receives The balance used in the laboratory has To accelerate his work, Facer tries to use the minimum steps to finish the weighing. For each step he can put one poise on the top of the stack (as long as no poises in the stack is lighter than it) or remove the poise which is currently on the top. Input The first line of the input contains the number of the test cases. - One line contains an integer
*N*(1 ≤*N*≤ 15), the number of different kinds of poises - One line contains
*N*integers,*W*_{1},*W*_{2}...*W*, ( 1 ≤_{N}*W*≤ 30)_{i} - One line contains an integer
*M*(1 ≤*M*≤ 500), the number of requests - One line contains
*M*integers,*R*_{1},*R*_{2}, ...*R*( 1 ≤_{M}*R*≤ 30)_{i}
Output For each test case, output a line containing the minimum number of steps Facer needed to finish all the requests. If any request can not be weighed out, output -1 instead. Sample Input 2 3 1 2 3 3 4 5 6 2 3 4 3 1 6 8 Sample Output 4 -1 Source |

[Submit] [Go Back] [Status] [Discuss]

All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di

Any problem, Please Contact Administrator