• hdu 5375 Gray code dp


    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    using namespace std;
    const int N=200000+5;
    const int inf=1<<24;
    int dp[N][2],a[N];
    char s[2*N];
    
    int main()
    {
        int n,m,i,_;
        scanf("%d",&_);
        for(int k=1;k<=_;k++)
        {
            scanf("%s",s);
            n=strlen(s);
            for(i=0;i<n;i++)
                scanf("%d",&a[i]);
            dp[0][0]=dp[0][1]=-inf;
            if(s[0]=='0'||s[0]=='?')
                dp[0][0]=0;
            if(s[0]=='1'||s[0]=='?')
                dp[0][1]=a[0];
    
            for(i=1;i<n;i++)
            {
                dp[i][0]=dp[i][1]=-inf;
                if(s[i]=='0'||s[i]=='?')
                    dp[i][0]=max(dp[i-1][0],dp[i-1][1]+a[i]);
                if(s[i]=='1'||s[i]=='?')
                    dp[i][1]=max(dp[i-1][1],dp[i-1][0]+a[i]);
            }
            printf("Case #%d: %d
    ",k,max(dp[n-1][0],dp[n-1][1]));
        }
        return 0;
    }

    版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/

  • 相关阅读:
    Game Engine Architecture 3
    Game Engine Architecture 2
    补码
    工厂模式
    Game Engine Architecture 1
    YDWE Keynote
    3D Math Keynote 4
    3D Math Keynote 3
    3D Math Keynote 2
    OGRE中Any 类型的实现
  • 原文地址:https://www.cnblogs.com/xryz/p/4847843.html
Copyright © 2020-2023  润新知