期望得分:100+100+30=230
实际得分:
正解:
枚举最高的位,这一位m是1但实际用了0
然后剩余的低位肯定是 正数就用1,负数用0
考场思路:数位DP
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; typedef long long LL; #define N 100001 int a[N]; char s[N]; LL dp[N][2]; void read(int &x) { x=0; int f=1; char c=getchar(); while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); } while(isdigit(c)) { x=x*10+c-'0'; c=getchar(); } x*=f; } LL dfs(int dep,int num,bool lim) { if(!dep) return 0; if(!lim && dp[dep][num]!=-1) return dp[dep][num]; int up= lim ? s[dep]-'0' : 1; LL res=0; res=dfs(dep-1,0,lim && 0==s[dep]-'0'); if(up) res=max(res,a[dep]+dfs(dep-1,1,lim && 1==s[dep]-'0')); if(!lim) dp[dep][num]=res; return res; } int main() { freopen("maximum.in","r",stdin); freopen("maximum.out","w",stdout); int n; read(n); for(int i=1;i<=n;i++) read(a[i]); scanf("%s",s+1); memset(dp,-1,sizeof(dp)); cout<<dfs(n,0,1); }