Game of cards
Practice
0 (0 votes)
Dynamic programming
Combinatorics
Grammar Verified
Hard
Recruit
Probability and statistics
Hiring
Bitmask
Algorithms
Bit manipulation
Mathematics
Counting and arrangements
Approved
Problem
40% Success 10 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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 \(X^{th}\) 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 \( X^{th}\) card being the last-remaining card in the game.

Constraints

\(1 ≤ N ≤ 14\)
\(1 ≤ X ≤ N\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
1 votes
Tags:
Basic ProgrammingDynamic ProgrammingCombinatoricsMathCounting and ArrangementsAlgorithms
Points:50
4 votes
Tags:
MathematicsDynamic ProgrammingOpenApprovedHard
Points:50
2 votes
Tags:
AlgorithmsCounting and ArrangementsDynamic ProgrammingMath