A1040 | Hoof Paper Scissors
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
You have probably heard of the game "Rock, Paper, Scissors". The cows like to
play a similar game they call "Hoof, Paper, Scissors".
The rules of "Hoof, Paper, Scissors" are simple. Two cows play against each-
other. They both count to three and then each simultaneously makes a gesture
that represents either a hoof, a piece of paper, or a pair of scissors. Hoof
beats scissors (since a hoof can smash a pair of scissors), scissors beats
paper (since scissors can cut paper), and paper beats hoof (since the hoof can
get a papercut). For example, if the first cow makes a "hoof" gesture and the
second a "paper" gesture, then the second cow wins. Of course, it is also
possible to tie, if both cows make the same gesture.
Farmer John wants to play against his prize cow, Bessie, at $N$ games of
"Hoof, Paper, Scissors" ($1 \leq N \leq 100,000$). Bessie, being an expert at
the game, can predict each of FJ's gestures before he makes it. Unfortunately,
Bessie, being a cow, is also very lazy. As a result, she tends to play the
same gesture multiple times in a row. In fact, she is only willing to switch
gestures at most $K$ times over the entire set of games ($0 \leq K \leq 20$).
For example, if $K=2$, she might play "hoof" for the first few games, then
switch to "paper" for a while, then finish the remaining games playing "hoof".
Given the sequence of gestures FJ will be playing, please determine the
maximum number of games that Bessie can win.
play a similar game they call "Hoof, Paper, Scissors".
The rules of "Hoof, Paper, Scissors" are simple. Two cows play against each-
other. They both count to three and then each simultaneously makes a gesture
that represents either a hoof, a piece of paper, or a pair of scissors. Hoof
beats scissors (since a hoof can smash a pair of scissors), scissors beats
paper (since scissors can cut paper), and paper beats hoof (since the hoof can
get a papercut). For example, if the first cow makes a "hoof" gesture and the
second a "paper" gesture, then the second cow wins. Of course, it is also
possible to tie, if both cows make the same gesture.
Farmer John wants to play against his prize cow, Bessie, at $N$ games of
"Hoof, Paper, Scissors" ($1 \leq N \leq 100,000$). Bessie, being an expert at
the game, can predict each of FJ's gestures before he makes it. Unfortunately,
Bessie, being a cow, is also very lazy. As a result, she tends to play the
same gesture multiple times in a row. In fact, she is only willing to switch
gestures at most $K$ times over the entire set of games ($0 \leq K \leq 20$).
For example, if $K=2$, she might play "hoof" for the first few games, then
switch to "paper" for a while, then finish the remaining games playing "hoof".
Given the sequence of gestures FJ will be playing, please determine the
maximum number of games that Bessie can win.
输入格式
The first line of the input file contains $N$ and $K$.
The remaining $N$ lines contains FJ's gestures, each either H, P, or S.
The remaining $N$ lines contains FJ's gestures, each either H, P, or S.
输出格式
Print the maximum number of games Bessie can win, given that she can only
change gestures at most $K$ times.
change gestures at most $K$ times.
输入输出样例
输入 #1
5 1 P P H P S
输出 #1
4
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted