#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> #define maxn 200005 #define ll __int64 #define INF 0xfffffff using namespace std; ll ans[maxn][2]; char s[maxn]; int a[maxn]; int main(){ int T; scanf("%d",&T); int ii=1; while(T--){ scanf("%s",s); int len=strlen(s); for(int i=0;i<len;i++) scanf("%d",&a[i]); memset(ans,-1,sizeof(ans)); ans[0][0]=0; for(int i=0;i<len;i++){ if(s[i]=='0') ans[i+1][0]=max(ans[i][0],(ans[i][1]==-1?-INF:ans[i][1])+a[i]); else if(s[i]=='1') ans[i+1][1]=max(ans[i][1],(ans[i][0]==-1?-INF:ans[i][0])+a[i]); else{ ans[i+1][0]=max(ans[i][0],(ans[i][1]==-1?-INF:ans[i][1])+a[i]); ans[i+1][1]=max(ans[i][1],(ans[i][0]==-1?-INF:ans[i][0])+a[i]); } } printf("Case #%d: %I64d\n",ii++,max(ans[len][0],ans[len][1])); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/mitic/article/details/47423289