我们可以先从后面算起来得出苹果的个数,在从开头计算价钱
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
char str[50][10];
int main(){
int n,p;
cin>>n>>p;
for(int i=0;i<n;i++) scanf("%s",str[i]);
ll num=0;
for(int i=n-1;i>=0;i--){
if(!strcmp(str[i],"halfplus")) num=num*2+1;
else num*=2;
}
ll ans=0;
for(int i=0;i<n;i++){
if(!strcmp(str[i],"halfplus")){
num/=2;
ans+=num*p+p/2;
}
else{
num/=2;
ans+=num*p;
}
}
cout<<ans<<endl;
}