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. activity堆栈式管理

    package com.chinaCEB.cebActivity.utils; import java.util.Stack; import android.app.Activity; import ...

  2. ElasticSearch学习笔记(五)-- 排序、分页与遍历

    1. 相关性算分 这样能够查询到不同分片上的文档的准确算分,默认分片为5 2. sorting-doc-values-fielddata 3. 分页与遍历

  3. build dynamic libraries for iOS and load them at runtime

    编译了libmt.dylib, 和 test 程序调用,均正常.在xcode中显示调用正常,隐式调用则出现问题. 提示 dyld: Library not loaded. 即使存在在/usr/lib/ ...

  4. Android学习记录(9)—Android之Matrix的用法

    Matrix ,中文里叫矩阵,高等数学里有介绍,在图像处理方面,主要是用于平面的缩放.平移.旋转等操作. 首先介绍一下矩阵运算.加法和减法就不用说了,对应位相加就好.图像处理,主要用到的是乘法 .下面 ...

  5. 转载: keepalived工作原理和配置说明

    转自:http://outofmemory.cn/wiki/keepalived-configuration keepalived是什么 keepalived是集群管理中保证集群高可用的一个服务软件, ...

  6. 剑指Offer - 九度1356 - 孩子们的游戏(圆圈中最后剩下的数)

    剑指Offer - 九度1356 - 孩子们的游戏(圆圈中最后剩下的数)2014-02-05 19:37 题目描述: 每年六一儿童节,JOBDU都会准备一些小礼物去看望孤儿院的小朋友,今年亦是如此.H ...

  7. mysql错误:Column ‘id’ in field list is ambiguous的解决方法

    [Err] 1052 - Column 'modify_time' in where clause is ambiguous 出错的语句: SELECT AVG(T.se)%60FROM( SELEC ...

  8. Robot Framwork +Selenium2环境搭建

    Robot Framwork +Selenium2环境搭建 安装python 参考文章http://blog.csdn.net/sealion111/article/details/78690686 ...

  9. IOS与Unity交互

    学习了宣雨松的两篇Unity和IOS交互的文章,自己动手做了下,遇到了些问题,在此记录 先说IOS发送消息给Unity:(文章地址:http://www.xuanyusong.com/archives ...

  10. Thread 线程池

    Thread 线程池: 当使用多个较短存活期的线程有利时,运用线程池技术可以发挥作用.运用这一技术时,不是为每个任务创建一个全新的线程,而可以从线程池中抽出线程,并分配给任务.当线程完成任务后,再把它 ...