NC207729. BlackandWhiteBoxes
描述
输入描述
The input consists of a single test case, formatted as follows.np1...pnA positive integer n (≤ 40) is the number of candidate piles. Each piis a string of characters Band W, representing the i-th candidate pile. B and W mean black and white boxes, respectively.They appear in the order in the pile, from bottom to top. The number of boxes in a candidatepile does not exceed 40.
输出描述
Output in a line the maximum possible number of boxes in a fair initial configuration consistingof some of the candidate piles. If only the empty configuration is fair, output a zero.
示例1
输入:
4 B W WB WB
输出:
5
示例2
输入:
6 B W WB WB BWW BWW
输出:
10