Cards

Taha has got a standard deck of cards with him. In addition to the 52 regular ones, there are 2 joker cards. Every regular card has a rank and a suit. The ranks in ascending order are: A, 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q and K. The suit of a card can be clubs, diamonds, hearts or spades. That means there are 13 clubs, 13 diamonds, 13 hearts and 13 spades — which adds up to 52. The joker cards have no ranks or suits. One day, Sara gave Taha a challenge. First she randomly shuffles the 54 cards and starts placing one card after another, face-up, on a table. What is the expected number of cards Sara has to place so that there are at least C clubs, D diamonds, H hearts and S spades on the table? Whenever a joker card is encountered, Taha has to assign it to some suit so that the expected number of cards to reach the goal is minimized. The decision of assigning the joker card to some suit has to be made instantly (i.e. before Sara puts the next card on the table). Note that the assignments of the two joker cards don’t necessarily need to be the same. Input First line of input is an integer T (T < 50) that indicates the number of test cases. Each case consists of a line containing 4 integers in the order C, D, H and S. Each of these integers will be in the range [0, 15]. Output For each case, output the case number first. Then output the expected number of cards Sara needs to place on the table to achieve the goal (rounded to 3 decimal places). If it’s impossible to reach the goal, irrespective of what assignments Sara opts for, output ‘-1.000’ (without the quotes) instead. Look at samples for exact format. Judge inputs are such that small precision errors won’t cause error in the output. If the output is ‘0.000’, make sure that you don’t print it as ‘–0.000’ (without the quotes). Illustration of the Samples:

  1. There is no need to place any card as all required values are 0 2) We must place all the 54 cards to reach the goal
  2. Note that output isn’t always an integer
  3. 60 Cards? No way!! Sample Input 4 0000 15 13 13 13 1234 15 15 15 15

2/2 Sample Output Case 1: 0.000 Case 2: 54.000 Case 3: 16.393 Case 4: -1.000