Dinner Bet
Time limit2sMemory limit512 MB
Given N balls, D drawn per round, and two size-C cards, find the expected number of rounds until one player completes their card.
- Level
Medium7 of 10
- Topics
- Probability, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
Cesar and Raul like betting and good food. They want to try a new fancy restaurant, so they agreed to play a game and let the loser pay for dinner.
A box holds balls, and each ball carries a distinct number between and . The game runs by these rules.
- At the start, each person picks distinct numbers between and and writes them on his own card.
- In each round, balls are drawn from the box. Every choice of balls is equally likely. Cesar and Raul mark the drawn numbers that appear on their own cards. The balls then go back into the box.
- The game stops in the round where a player has marked every number on his card, and that player wins. If both players finish in the same round, the game is a draw and they split the dinner.
You are given the number of balls , the number of balls drawn each round , the card size , and the numbers the two players wrote down. Find the expected number of rounds the game lasts.
Input
The first line contains three space separated integers , , and . The second line contains the numbers Cesar wrote down, and the third line contains the numbers Raul wrote down, both space separated. The numbers on one line are distinct.
Output
Print the expected number of rounds the game lasts on one line, rounded to five digits after the decimal point.
Constraints
- : the number of balls in the box
- : the number of balls drawn each round
- : the card size
- Every number written on a card is between and , and the numbers on one card are distinct.