The minimum cost

3.9

30 votes
Bit Manipulation, Basic Programming, Basics of Bit Manipulation
Problem

You are given a binary array (array consists of 0s and 1s) A that contains N elements. You can perform the following operation as many time as you like:

  1.  Choose any index  1iN and if it is currently 0, then convert it to 1 for C01 coins.
  2.  Choose any index  1iN and if it is currently 1, then convert it to 0 for C10 coins.

Your task is to transform the given array into a special array that for every index 1i<N, AiAi+1=1.

Here,  denotes XOR.

Input format

  • The first line contains T the number of test cases.
  • The first line of each test case contains three space-separated integers N, C01 and C10.
  • The second line consists of N space-separated integers of array A.

Output format

For each test case, print one line denoting the minimum cost to transform array A into a special array.

Constraints

1T100

1N10000

0A[i]1i[1,N]

1C01,C101e9

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In first test case we can convert first 1 to 0 costing 1 coin.

In second test it is already special.

Editor Image

?