CT063

Markov Chain States

HardAcceptance: 0.0%

A Markov chain describes probabilities of transitioning between states. Given a starting state, transition probabilities, and a number of steps, simulate the chain and return the count of visits to each state. Input: first line start state and num_steps, second line n (number of transitions), then n lines "from to probability", then seed. Output: counts for each state visited.

Example 1:

Input: a 1000 3 a a 0.9 a b 0.075 a c 0.025 b a 0.15 b b 0.8 b c 0.05 c a 0.25 c b 0.25 c c 0.5 42
Output: a 900 b 75 c 25

Constraints:

1 <= num_steps <= 10^4 States are single lowercase letters 0 < probability < 1 Probabilities from each state sum to 1

Tags:

randomized-algorithm simulation probability
Loading...
Test Cases:No test cases
No test cases available.