After a long time of effort, RoBa still keeps single. He finds that all the girls are so hard to understand. They can become happy in one minute, and then get angry in the next. What’s more, what they do is usually quite different from what they think!
As an algorithmic geek, RoBa builds a probability model to study a girl’s behavior. That is, there are N kinds of inner states for one girl. At the beginning, the girl can be at state i with probability Si. Then at every minute after that, the girl’s state can be changed from state i to state j with probability Pij. Of course, S1+S2+…+SN = 100 (in percent), and for all the i, Pi1+Pi2+…+PiN=100
And that’s still not practical enough. RoBa knows that he cannot see the inner state of a girl directly, but can only see her outer behavior. There are M kinds of behaviors, and when a girl is at state i, she will take behavior k with probability Aik. And again, for all the i, Ai1+Ai2+…+AiM=100
Now, given a sequence of a girl’s outer behavior and all the probabilities describe above (we don’t know how RoBa get them!), can you help him to find out the girl’s most probable inner state sequence?
For example, as the figure above described, RoBa observes a girl for three minutes, and the behavior sequence is laugh -> Silent -> Silent. Then the poor boy wants to guess the girl’s real state. Let’s suppose he make a guess that the girl’s inner state sequence is happy -> sad -> happy. With the probabilities above, he can find its possibility is SHappy * AHappy,Laugh * PHappy,Sad * ASad,Silent * PSad,Happy * AHappy,Silent. So RoBa can calculate the possibility of all the inner state sequence, for example, sad->sad->happy, happy->happy->happy, and so on. Then he just simply picks the sequence with the highest possibility as the answer. Of course, this will cost too much time, so RoBa need a more clever algorithm to achieve the same result.
To be more formally, given a girl’s outer behavior sequence (B1, B2, … BT), it is natural that the possibility of a girl’s inner sequence (C1, C2, … CT) is
Don’t be scared of the formula above, it just describe our intuition precisely. This problem is not such difficult as it seems, believe me .