4760: [Usaco2017 Jan]Hoof, Paper, Scissors

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 136  Solved: 100
[Submit][Status][Discuss]

Description

You have probably heard of the game "Rock, Paper, Scissors". The cows like to play a similar game th
ey call "Hoof, Paper, Scissors"
你可能玩过石头剪刀布这个游戏,奶牛们也喜欢玩类似的游戏,叫做“蹄子剪刀布”
The rules of "Hoof, Paper, Scissors" are simple. Two cows play against each-other. They both count t
o 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 b
eats 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 sec
ond 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≤N
≤100,000). Bessie, being an expert at the game, can predict each of FJ's gestures before he makes i
t. Unfortunately, Bessie, being a cow, is also very lazy. As a result, she tends to play the same ge
sture multiple times in a row. In fact, she is only willing to switch gestures at most KK times over
 the entire set of games (0≤K≤20). For example, if K=2, she might play "hoof" for the first few ga
mes, then switch to "paper" for a while, then finish the remaining games playing "hoof".
 
现在FJ想要和他的最机智的奶牛Bessie玩蹄子剪刀布(我也不知道FJ为什么有蹄子),一共进行了N轮(N<=1e5),B
essie,作为一个奶牛,非常的怠惰,无论她出什么,都喜欢连续的出,最多变化K次(K<=20),也就是说,对于她
所出的,记为序列f(i),记sum=有多少个i满足f(i)!=f(i-1)(i>1),而她的sum一定不会超过k
Given the sequence of gestures FJ will be playing, please determine the maximum number of games that
 Bessiecan win.
 
现在FJ已经给出了他出的东西,你要告诉Bessie,在不确定她出的东西的情况下,她最多能赢多少次
 

Input

The first line of the input file contains N and K.
输入数据第一行为N,K
The remaining N lines contains FJ's gestures, each either H, P, or S
接下来N行表示FJ所出的东西,H表示hoof,P表示paper,S表示Scissors
 

Output

 
Print the maximum number of games Bessie can win, given that she can only change gestures at most KK times.
输出在变化不超过K次的前提下,最多能赢多少次
 

Sample Input

5 1
P
P
H
P
S

Sample Output

4

HINT

 

Source

Gold

sbdp题。

 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;
int n,K;
char s[];
int c[];
int f[][][];//1->0 0->2 2->1
int main() {
scanf("%d%d",&n,&K);
for(int i=;i<=n;i++) {
scanf("%s",s);
if(s[]=='H') c[i]=;
if(s[]=='P') c[i]=;
if(s[]=='S') c[i]=;
}
f[][][c[]]=;
for(int i=;i<=n;i++) {
for(int j=;j<=min(K,i);j++) {
for(int k=;k<;k++) {
if(k==c[i]) f[i][j][k]=max(f[i][j][k],f[i-][j][k]+);
else {
f[i][j][k]=f[i-][j][k];
f[i][j][c[i]]=max(f[i][j][c[i]],f[i-][j-][k]+);
}
}
}
}
int ans=;
for(int i=;i<=K;i++)
for(int j=;j<;j++) ans=max(ans,f[n][i][j]);
printf("%d",ans);
}

[BZOJ4760][Usaco2017 Jan]Hoof, Paper, Scissors dp的更多相关文章

  1. bzoj4760[USACO2017 Jan]Hoof,Paper,Scissors

    题意:玩n次剪刀石头布,对方每次出什么已经知道了.你出的招数必须是连续的几段(不能超过k+1段),问你最多赢几次.(n<=100000,k<=20) 正常做法:f[i][j][k]表示前i ...

  2. bzoj4758: [Usaco2017 Jan]Subsequence Reversal(区间dp)

    4758: [Usaco2017 Jan]Subsequence Reversal Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 76  Solved ...

  3. Hoof, Paper, Scissors(USACO)

    题目大意: 一种游戏(类似于石头剪刀布):两个人分别给出一个字母,然后比较:H>S,S>P,P>H,我们已知对手的字母顺序,求在前n局中我们最多能赢多少次. 由于出字母的人非常懒,所 ...

  4. 洛谷 P3609 [USACO17JAN]Hoof, Paper, Scissor蹄子剪刀…

    P3609 [USACO17JAN]Hoof, Paper, Scissor蹄子剪刀… 题目背景 欢迎提供翻译,请直接在讨论区发帖,感谢你的贡献. 题目描述 You have probably hea ...

  5. 1090-Rock, Paper, Scissors

    描述 Rock, Paper, Scissors is a classic hand game for two people. Each participant holds out either a ...

  6. BZOJ_2580_[Usaco2012 Jan]Video Game_AC自动机+DP

    BZOJ_2580_[Usaco2012 Jan]Video Game_AC自动机+DP Description Bessie is playing a video game! In the game ...

  7. BZOJ_4756_[Usaco2017 Jan]Promotion Counting_树状数组

    BZOJ_4756_[Usaco2017 Jan]Promotion Counting_树状数组 Description n只奶牛构成了一个树形的公司,每个奶牛有一个能力值pi,1号奶牛为树根. 问对 ...

  8. 2018 ACM-ICPC 中国大学生程序设计竞赛线上赛 H题 Rock Paper Scissors Lizard Spock.(FFT字符串匹配)

    2018 ACM-ICPC 中国大学生程序设计竞赛线上赛:https://www.jisuanke.com/contest/1227 题目链接:https://nanti.jisuanke.com/t ...

  9. [BZOJ4756][Usaco2017 Jan]Promotion Counting 树状数组

    4756: [Usaco2017 Jan]Promotion Counting Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 305  Solved: ...

随机推荐

  1. luogu3317 [SDOI2014]重建

    原来矩阵树定理对于边是概率的情况也是适用的qwqwq. ref #include <iostream> #include <cstdio> #include <cmath ...

  2. 剑指Offer - 九度1214 - 丑数

    剑指Offer - 九度1214 - 丑数2013-11-21 21:06 题目描述: 把只包含因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因为它包含因子7. ...

  3. 《Cracking the Coding Interview》——第1章:数组和字符串——题目2

    2014-03-18 01:30 题目:反转一个char *型的C/C++字符串. 解法:一头一尾俩iterator,向中间靠拢并且交换字符. 代码: // 1.2 Implement a funct ...

  4. (原)UE4 制作执行队列(Action Queue)

    队列和树在游戏开发中是比较常见的数据结构,在一定范围能保证执行的顺序. 结合一些设计模式技巧,往往可以做一些神器.     如加载块chunk管理,任务系统(当然也可以使用行为树来做复杂的任务系统). ...

  5. 上手Caffe(一)

    @author:oneBite 本文记录编译使用caffe for windows 使用环境 VS2013 ultimate,win7 sp1,caffe-windows源码(从github上下载ca ...

  6. PCA学习笔记

    主成分分析(Principal Component Analysis,简称PCA)是最常用过的一种降维方法 在引入PCA之前先提到了如何使用一个超平面对所有的样本进行恰当的表达? 即若存在这样的超平面 ...

  7. 爬虫:Scrapy16 - Spider Contracts

    Scrapy 通过合同(contract)的方式来提供了测试 spider 的集成方法. 可以硬编码(hardcode)一个样例(sample)url,设置多个条件来测试回调函数处理 response ...

  8. cygwin安装apt-cyg

    lynx -source rawgit.com/transcode-open/apt-cyg/master/apt-cyg > apt-cyg install apt-cyg /bin

  9. MPLAB设置路径

    大家都知道在MPLAB环境下编译程序,c文件.h文件.编译器生成的文件等等,都会被编译器无情的放在一个项目文件夹下. 稍微有些讲究的程序员可能就会觉得用MPLAB项目组织的一团糟.于是大家想到了一种方 ...

  10. 深入解析VueJs中的V-bind指令

    v-bind 主要用于属性绑定,比方你的class属性,style属性,value属性,href属性等等,只要是属性,就可以用v-bind指令进行绑定.这次主要介绍了VueJs中的V-bind指令,需 ...