404979: GYM101726 B Spy Duel

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

B. Spy Dueltime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Alexey and Boris were two KGB agents that lived in Ekaterinburg in the 70's. The city was pretty small, and as nothing happened, to avoid dying of boredom the agents decided to create a dice game. In that game each of them started with VA and VB hit points, respectively. Each had in their disposal some attacks, and they alternated in attacking each other. Each attack is described by a number of dice. To determine the damage of the attack, roll those dice and their sum is the damage.

To play, they have available honest dice with 1 to 12 faces. That is, if a die with L faces is rolled it will show an integer between 1 and L with the same probability, and independent of any dice rolled before.

Both players know their attack and their opponents and choose how to attack each turn in a way that will maximize their probability of winning. Your task is to determine that probability.

Input

In the first line an integer T, the number of test cases.

In the first line of each case, four integers VA, VB, NA and NB. Each of the next NA lines describes an attack Alexey has, the other NB lines describe the attacks Boris has.

Each attack is described by an integer D followed by D integers L1, ..., LD, meaning that to attack the player will roll D dice, with faces L1, ... LD.

Limits

  • 1 ≤ T ≤ 5
  • 1 ≤ VA, VB ≤ 300
  • 1 ≤ NA, NB ≤ 10
  • 1 ≤ D ≤ 3
  • 1 ≤ Li ≤ 12
Output

For each case, print a single line with the probability that Alexey will win the duel, assuming he starts and both players play optimally. It will be considered correct if the absolute or relative error does not exceed 10 - 6.

ExampleInput
2
2 12 2 1
1 12
3 4 4 5
2 1 1
5 5 1 2
1 6
2 3 5
2 1 6
Output
0.0833333333
0.5339917695

Source/Category

加入题单

上一题 下一题 算法标签: