AtCoder Beginner Contest 149 D.Prediction and Restriction

主宰稳场 提交于 2019-12-31 12:26:05

Problem Statement

(略)
题目来源

Output

Print the maximum total score earned in the game.

Sample Input 1

5 2
8 7 6
rsrpr

Sample Output 1

27

Sample Input 2

7 1
100 10 1
ssssppr

Sample Output 2

211

Sample Input 3

30 5
325 234 123
rspsspspsrpspsppprpsprpssprpsr

Sample Output 3

4996

比赛时一直挂,根本不知道错在哪里,赛后看了别人写的,感觉也没啥差别,不过我看到有写得很简便的方法,就在这边记录一下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
   int n,k,r,s,p;
   string T;
   int ans=0,vis[100005];
   memset(vis,0,sizeof(vis));
   cin>>n>>k>>r>>s>>p>>T;
    for(int i=0;i<n;i++){
          if(i-k>=0 && vis[i-k] && T[i]==T[i-k]) continue;
          if(T[i]=='r') ans+=p;
          if(T[i]=='s') ans+=r;
          if(T[i]=='p') ans+=s;
          vis[i]=1;
    }
    cout<<ans;
    return 0;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!