This page is still under construction.

Parts of this page are still being built. What you see may change.

Minimal Backgammon

Time limit1sMemory limit128 MB

Summary
Simulate turn by turn probability mass over board positions (with lose-a-turn and go-to-start squares, and bounce-back overshoot rule) to find probability of reaching the goal within T turns.
Level

Medium5 of 10

Topics
Dynamic programming, Simulation, Probability
Solved
No attempts yet

Problem

This is a very simple, single-player variant of backgammon called “Minimal Backgammon”. It is played by one player using a single die and a single checker (the player's token).

The board is a line of N+1N + 1 squares labeled 00 (the start) through NN (the goal). At the beginning the checker is placed on the start (square 00), and the aim is to bring the checker to the goal (square NN). On each turn the player rolls the die, which shows each of the integers 11 through 66 with equal probability, and the checker advances by that many squares.

The checker must not go beyond the goal. If a roll would bring the checker beyond the goal, the checker instead moves up to the goal and then retreats from the goal by the number of squares in excess. For example, if the checker is on square N−3N - 3, a roll of 55 brings it to square N−2N - 2, because the amount by which it would exceed the goal is 22. On the next turn it again proceeds toward the goal as usual.

Every square other than the start and the goal may carry one of the following two special instructions.

  • Lose one turn: if the checker stops here, you cannot move the checker on the next turn.
  • Go back to the start: if the checker stops here, the checker is immediately brought back to the start (square 00).

Given a board configuration (the size NN and the placement of the special squares), compute the probability that the game succeeds (the checker reaches the goal) within a given number of turns.

Input

The input consists of multiple datasets. Each dataset has the following format.

N T L B
Lose_1
...
Lose_L
Back_1
...
Back_B

NN is the index of the goal and satisfies 5≤N≤1005 \le N \le 100. TT is the number of turns; you must compute the probability of success within TT turns, and it satisfies 1≤T≤1001 \le T \le 100. LL is the number of squares marked “Lose one turn” and satisfies 0≤L≤N−10 \le L \le N - 1. BB is the number of squares marked “Go back to the start” and satisfies 0≤B≤N−10 \le B \le N - 1. These four values are separated by spaces.

Each value in the Lose list is the index of a square marked “Lose one turn” and satisfies 1≤1 \le value ≤N−1\le N - 1; the values are distinct and given in ascending order. Each value in the Back list is the index of a square marked “Go back to the start” and satisfies 1≤1 \le value ≤N−1\le N - 1; the values are distinct and given in ascending order. No index appears in both the Lose list and the Back list.

The end of the input is indicated by a line containing four zeros separated by spaces.

Output

For each dataset, print on a single line the probability that the game succeeds within the given number of turns, rounded to exactly six digits after the decimal point (for example, using printf("%.6f")).

Examples1

  1. Example 1

    Input
    6 1 0 0
    7 1 0 0
    7 2 0 0
    6 6 1 1
    2
    5
    7 10 0 6
    1
    2
    3
    4
    5
    6
    0 0 0 0
    
    Expected output
    0.166667
    0.000000
    0.166667
    0.619642
    0.000000