Rigged Rock-Paper-Scissors (Small)
InterviewTime limit1sMemory limit1024 MB
Count the non-empty subsequences of a rock-paper-scissors move string where no round won by lighter is immediately followed by a tie.
- Level
Medium5 of 10
- Topics
- Dynamic programming, String
- Solved
- No attempts yet
Round Count
In the Small version, the string length limit is .
A rock-paper-scissors championship is underway before a large crowd. lighter and smallant have reached the final. They have been close friends since childhood, so neither cares much who wins. For this final, they plan a prank.
The final consists of several rounds. Except in the first round, lighter plans to play whatever smallant played in the immediately previous round. The crowd hates this kind of prank. If lighter wins a round and the very next round is a tie, the audience will notice that the two are playing a prank and will be furious.
An angry crowd could end the championship's sponsorship, so smallant needs to reconsider what to play. After thinking it over, smallant realizes the problem is solved by taking only a part of the planned moves.
Taking only a part means that, given the planned moves as a string, some characters are removed without changing the order of the rest.
For example, suppose the final has 8 rounds. smallant plans to play the moves in Table 1 in order: paper, scissors, paper, scissors, paper, paper, rock, scissors. lighter plays rock in round 1 only, and copies smallant from round 2 onward.
In this case, lighter wins round 5 and the next round is a tie, so the crowd will be furious.
So in this case, smallant only needs to remove rounds 6 and 7 from the planned sequence paper, scissors, paper, scissors, paper, paper, rock, scissors, and play the remaining paper, scissors, paper, scissors, paper, scissors.
Given the moves smallant planned, count the ways to take only a part of them so that the crowd does not get angry. At least one round must remain.