提交时间:2024-11-10 22:08:56
运行 ID: 56388
#include<iostream> #include<algorithm> #include<cstdio> #include<queue> #include<stack> #include<cstring> using namespace std; int n,k,r,s,c; string t; char a[100]; int maxx=0; char rsc[]={'-','r','s','c'}; int cmp(char a,char b){//a应该加几分 if(a=='r'&&b=='s')return r; if(a=='c'&&b=='r')return c; if(a=='s'&&b=='c')return s; return 0; } void dfs(int x){ if(x==n){ int sum=0; for(int i=0;i<n;i++){ sum+=cmp(a[i],t[i]); } // printf("a:%s sum:%d\n",a,sum); maxx=max(maxx,sum); return; } for(int i=1;i<=3;i++){ if(x>k&&rsc[i]==a[x-k])continue; a[x]=rsc[i]; dfs(x+1); } return; } int main(){ cin>>n>>k>>r>>s>>c>>t; dfs(0); cout<<maxx; return 0; } /* #include<cstdio> freopen("文件名.in","r",stdin); freopen("文件名.out","w",stdout); */