Game of cards

0

0 votes
Dynamic Programming, Combinatorics, Grammar-Verified, Hard, Recruit, Probability and Statistics, Hiring, Bitmask, Algorithms, Bit manipulation, Mathematics, Counting and Arrangements, Approved
Problem

You are playing a game with N cards that are marked from 1 to N. The rules of the game are as follows:

  • In each turn, you remove some cards. The game goes on until only one card is left.
  • If the number of cards that are left is odd, then preserve the card with the smallest number and randomly remove half of the remaining available cards.
  • If the number of cards that are left is even, then randomly remove half of the available cards.

Write a program to determine the probability that the Xth card is the last one remaining.

Input format

The first and only line contains two space-separated integers N and X

Output format

Print the probability of the Xth card being the last-remaining card in the game.

Constraints

1N14
1XN

Sample Input
2 1
Sample Output
0.50000000
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In this case both cards have equal probability of being present in the end as well equal probability of being destroyed.

Editor Image

?