Prediction and Restriction——UPC

简介: 题目描述At an arcade, Takahashi is playing a game called RPS Battle, which is played as follows:·The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)

题目描述


At an arcade, Takahashi is playing a game called RPS Battle, which is played as follows:

·The player plays N rounds of Rock Paper Scissors against the machine. (See Notes for the description of Rock Paper Scissors. A draw also counts as a round.)

·Each time the player wins a round, depending on which hand he/she uses, he/she earns the following score (no points for a draw or a loss):

→R points for winning with Rock;

→S points for winning with Scissors;

→P points for winning with Paper.

·However, in the i-th round, the player cannot use the hand he/she used in the (i−K)-th round. (In the first K rounds, the player can use any hand.)

Before the start of the game, the machine decides the hand it will play in each round. With supernatural power, Takahashi managed to read all of those hands.

The information Takahashi obtained is given as a string T. If the i-th character of T (1≤i≤N)

is r, the machine will play Rock in the i-th round. Similarly, p and s stand for Paper and Scissors, respectively.

What is the maximum total score earned in the game by adequately choosing the hand to play in each round?


Notes

In this problem, Rock Paper Scissors can be thought of as a two-player game, in which each player simultaneously forms Rock, Paper, or Scissors with a hand.

·If a player chooses Rock and the other chooses Scissors, the player choosing Rock wins;

·if a player chooses Scissors and the other chooses Paper, the player choosing Scissors wins;

·if a player chooses Paper and the other chooses Rock, the player choosing Paper wins;

·if both players play the same hand, it is a draw.


Constraints

·2≤N≤105

·1≤K≤N−1

·1≤R,S,P≤104

·N,K,R,S, and P are all integers.

·|T|=N

·T consists of r, p, and s.


输入


Input is given from Standard Input in the following format:


N K
R S P
T


输出


Print the maximum total score earned in the game.


样例输入


【样例1】
5 2
8 7 6
rsrpr
【样例2】
7 1
100 10 1
ssssppr
【样例3】
30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr


样例输出


【样例1】
27
【样例2】
211
【样例3】
4996


提示


样例1解释

The machine will play {Rock, Scissors, Rock, Paper, Rock}.

We can, for example, play {Paper, Rock, Rock, Scissors, Paper} against it to earn 27 points. We cannot earn more points, so the answer is 27.

#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define wuyt main
typedef long long ll;
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
//#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
if(c == '-')Nig = -1,c = getchar();
while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
return Nig*x;}
#define read read()
const ll inf = 1e15;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
#define start int wuyt()
#define end return 0
int n, r, s, p, k;
int judge[1005];///ASCII从97--122其实开200就已经够了
char pr[maxn], gr[maxn];
start{
    /**
    ll n=read,m=read;
    char judge[10];
    ll cnt=0;
    while(m--){
        cin>>judge+1;
        if(judge[3]=='y'){
            if(cnt==0) printf("F\n");
            else if(cnt!=0) printf("T\n");
        }
        else if(judge[3]=='u') printf("%lld\n",cnt);
        else if(judge[3]=='n'){
            ll shu=read;
            if(num[shu]==0) printf("F\n");
            if(num[shu]==1) printf("T\n");
        }
        else if(judge[3]=='l'){
            ll temp=read;
            if(num[temp]==0){
                num[temp]=1;
                cnt++;
            }
            else if(num[temp]==1){
                num[temp]=0;
                cnt--;
            }
        }
    }
    **/
    n=read,k=read,r=read,s=read,p=read;
    judge['r']=r;
    judge['s']=s;
    judge['p']=p;
    cin>>pr+1;
    for (int i=1;i<=n;i++) {
        if (pr[i]=='s') pr[i]=gr[i]='r';
        else if (pr[i]=='p') pr[i] = gr[i] = 's';
        else pr[i]=gr[i]='p';
    }
    for (int i=1; i<=n;i++)
        if(i+k<=n&&gr[i]==gr[i+k])
            gr[i+k]='9';///重复
    int ans=0;
    for(int i=1;i<=n;i++)
        if(pr[i]==gr[i])
            ans+=judge[gr[i]];
    printf("%d\n", ans);
    end;
}
/**************************************************************
    Language: C++
    Result: 正确
    Time:11 ms
    Memory:2416 kb
****************************************************************/
目录
相关文章
Greedy Takahashi——UPC
题目描述 Takahashi has A cookies, and Aoki has B cookies. Takahashi will do the following action K times: ·If Takahashi has one or more cookies, eat one of his cookies. ·Otherwise, if Aoki has one or more cookies, eat one of Aoki’s cookies. ·If they both have no cookies, do nothing.
114 0
TimeInterval value and value2 determination in SalesPipeline
TimeInterval value and value2 determination in SalesPipeline
94 0
TimeInterval value and value2 determination in SalesPipeline
|
计算机视觉 Python
Improving the quality of the output
There are a variety of reasons you might not get good quality output from Tesseract. It's important to note that unless you're using a very unusual fo...
1071 0
|
算法
Whole-Genome Expression Microarray Combined with Machine Learning to Identify Prognostic Biomarke...
摘要 本研究的目的是建立一个框架,以更好地了解高级别胶质瘤(HGG)预后相关的生物标志物。进行全基因组基因表达微阵列以鉴定HGG和低级弥漫性神经胶质瘤之间的差异表达基因。
1424 0
|
机器学习/深度学习 算法 前端开发
文献翻译:Statistical Approaches for Gene Selection, Hub Gene Identification and Module Interaction in...
摘要 信息基因的选择是基因表达研究中的重要问题。基因表达数据的小样本量和大量基因特性使选择过程复杂化。此外,所选择的信息基因可以作为基因共表达网络分析的重要输入。
1170 0
|
资源调度 算法
论文阅读之 DECOLOR: Moving Object Detection by Detecting Contiguous Outliers in the Low-Rank Representation
DECOLOR: Moving Object Detection by Detecting Contiguous Outliers in the Low-Rank Representation Xiaowei Zhou et al.
1373 0
[Bhatia.Matrix Analysis.Solutions to Exercises and Problems]PrI.6.1
Given a basis $U=(u_1,\cdots,u_n)$ not necessarily orthonormal, in $\scrH$, how would you compute the biorthogonal basis $\sex{v_1,\cdots,v_n}$? Find ...
672 0
|
应用服务中间件 AHAS Perl
[Bhatia.Matrix Analysis.Solutions to Exercises and Problems]ExI.5.6
Let $A$ be a nilpotent operator. Show how to obtain, from aJordan basis for $A$, aJordan basis of $\wedge^2A$.
768 0