Codeforces Round #205 (Div. 2)C 选取数列可以选择的数使总数最大——dp
Posted on 2013-10-11 13:50 huhuuu 阅读(442) 评论(0) 编辑 收藏 举报http://codeforces.com/contest/353/problem/C
Codeforces Round #205 (Div. 2)C
#include<stdio.h> int s[109999]; int dp[109999]; char str[109999]; int Max(int a,int b){ if(a<b)return b; else return a; } int main(){ int n; while(scanf("%d",&n)!=EOF){ int i; dp[0]=0; for(i=1;i<=n;i++){ scanf("%d",&s[i]); dp[i]=dp[i-1]+s[i]; } scanf("%s",str); int all=0,max=0; for(i=n-1;i>=0;i--){ if(str[i]=='0')continue; max=Max(max,all+dp[i]); all+=s[i+1]; } max=Max(all,max); printf("%d\n",max); } return 0; }