#QHD0000030. Móng, giấy, kéo (Hoof, Paper, Scissors)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Móng, giấy, kéo (Hoof, Paper, Scissors)
Hoof, Paper, Scissors
Source: USACO
Version: Phuoc Hung OJ Extended
Problem Statement
Bessie plays games of Hoof, Paper, Scissors and knows all the opponent’s moves in advance.
In each game, Bessie chooses H (hoof), P (paper), or S (scissors). H beats S, S beats P, and P beats H. Bessie may keep a gesture for several games, but may change gestures between consecutive games at most times.
Find the maximum number of games Bessie can win.
Input
The first line contains and .
Each of the next lines contains one of H, P, or S, the opponent’s gesture in that game.
Output
Print the maximum number of games Bessie can win.
Subtasks
- Subtask 1 (20 points): ; ; Each input gesture is one of
H,P,S. - Subtask 2 (30 points): ; ; Each input gesture is one of
H,P,S. - Subtask 3 (50 points): ; ; Each input gesture is one of
H,P,S.
Examples
Input
5 1
P
P
H
P
S
Output
4
Explanation
The opponent plays P, P, H, P, S. Bessie can use S in the first four games, then switch to H for the last game. Bessie wins games , , , and : four wins with only one gesture change.