CF865F.Egg Roulette

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

The game of Egg Roulette is played between two players. Initially 2R2R raw eggs and 2C2C cooked eggs are placed randomly into a carton. The shells are left on so there is no way to distinguish a raw egg from a cooked egg. One at a time, a player will select an egg, and then smash the egg on his/her forehead. If the egg was cooked, not much happens, but if the egg was raw, it will make quite the mess. This continues until one player has broken RR raw eggs, at which point that player is declared the loser and the other player wins.

The order in which players take turns can be described as a string of 'A' and 'B' characters, where the ii -th character tells which player should choose the ii -th egg. Traditionally, players take turns going one after the other. That is, they follow the ordering "ABABAB...". This isn't very fair though, because the second player will win more often than the first. We'd like you to find a better ordering for the players to take their turns. Let's define the unfairness of an ordering as the absolute difference between the first player's win probability and the second player's win probability. We're interested in orderings that minimize the unfairness. We only consider an ordering valid if it contains the same number of 'A's as 'B's.

You will also be given a string SS of length 2(R+C)2(R+C) containing only 'A', 'B', and '?' characters. An ordering is said to match SS if it only differs from SS in positions where SS contains a '?'. Of the valid orderings that minimize unfairness, how many match SS ?

输入格式

The first line of input will contain integers RR and CC (1<=R,C<=20,R+C<=30)(1<=R,C<=20,R+C<=30) .

The second line of input will contain the string SS of length 2(R+C)2(R+C) consisting only of characters 'A', 'B', '?'.

输出格式

Print the number of valid orderings that minimize unfairness and match SS .

输入输出样例

  • 输入#1

    1 1
    ??BB
    

    输出#1

    0
    
  • 输入#2

    2 4
    ?BA??B??A???
    

    输出#2

    1
    
  • 输入#3

    4 14
    ????A??BB?????????????AB????????????
    

    输出#3

    314
    

说明/提示

In the first test case, the minimum unfairness is 00 , and the orderings that achieve it are "ABBA" and "BAAB", neither of which match SS . Note that an ordering such as "ABBB" would also have an unfairness of 00 , but is invalid because it does not contain the same number of 'A's as 'B's.

In the second example, the only matching ordering is "BBAAABABABBA".

首页