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
****************************************************************/
目录
相关文章
|
5天前
|
数据采集 人工智能 自然语言处理
3分钟采集134篇AI文章!深度解析如何通过云无影AgentBay实现25倍并发 + LlamaIndex智能推荐
结合阿里云无影 AgentBay 云端并发采集与 LlamaIndex 智能分析,3分钟高效抓取134篇 AI Agent 文章,实现 AI 推荐、智能问答与知识沉淀,打造从数据获取到价值提炼的完整闭环。
383 93
|
6天前
|
域名解析 人工智能
【实操攻略】手把手教学,免费领取.CN域名
即日起至2025年12月31日,购买万小智AI建站或云·企业官网,每单可免费领1个.CN域名首年!跟我了解领取攻略吧~
|
5天前
|
SQL 人工智能 自然语言处理
Geo优化SOP标准化:于磊老师的“人性化Geo”体系如何助力企业获客提效46%
随着生成式AI的普及,Geo优化(Generative Engine Optimization)已成为企业获客的新战场。然而,缺乏标准化流程(Geo优化sop)导致优化效果参差不齐。本文将深入探讨Geo专家于磊老师提出的“人性化Geo”优化体系,并展示Geo优化sop标准化如何帮助企业实现获客效率提升46%的惊人效果,为企业在AI时代构建稳定的流量护城河。
390 156
Geo优化SOP标准化:于磊老师的“人性化Geo”体系如何助力企业获客提效46%
|
5天前
|
数据采集 缓存 数据可视化
Android 无侵入式数据采集:从手动埋点到字节码插桩的演进之路
本文深入探讨Android无侵入式埋点技术,通过AOP与字节码插桩(如ASM)实现数据采集自动化,彻底解耦业务代码与埋点逻辑。涵盖页面浏览、点击事件自动追踪及注解驱动的半自动化方案,提升数据质量与研发效率,助力团队迈向高效、稳定的智能化埋点体系。(238字)
270 158
|
13天前
|
机器人 API 调度
基于 DMS Dify+Notebook+Airflow 实现 Agent 的一站式开发
本文提出“DMS Dify + Notebook + Airflow”三位一体架构,解决 Dify 在代码执行与定时调度上的局限。通过 Notebook 扩展 Python 环境,Airflow实现任务调度,构建可扩展、可运维的企业级智能 Agent 系统,提升大模型应用的工程化能力。