• 题解【DP100题1~10】


    这事做晚了

    (Dp100计划T1)

    只有蓝题及以上才会水题解

    分行Dp,行间没有转移

    [F[L][R] = max(F[L+1][R]+2^k imes V[L],F[L][R-1]+2^k imes V[R]) ]

    #include<iostream>
    #include<cstdio>
    #include<vector>
    #include<stack>
    #include<algorithm>
    #include<cstring>
    #define ll __int128
    #define MAXN 85
    ll f[MAXN][MAXN] ;
    ll pow2[MAXN] ;
    ll val[MAXN] ;
    ll ans = 0 ; 
    ll n,m ;
    using namespace std ;
    #define k m-(R-L)
    ll dp(int L,int R){
        if(f[L][R]!=-1) return f[L][R];
        if(R-L>=1) f[L][R]=max(val[L]*pow2[k]+dp(L+1,R),dp(L,R-1)+val[R]*pow2[k]);
        else f[L][R]=val[L]*pow2[k];
        return f[L][R];
    }
    void put(ll v){ if(v>9) put(v/10) ; putchar(v%10+'0') ; }
    void pput(ll v){ if(!v) putchar('0') ; else put(v) ; }
    inline void read(ll &x) { char ch=getchar(); int f=1; ll s=0 ; while (!(ch>='0'&&ch<='9')) { if (ch=='-') f=-1; ch=getchar();} while (ch>='0'&&ch<='9') { s=(s<<3)+(s<<1)+ch-'0'; ch=getchar(); } x=s*f; }
    int main(){
        read(n) , read(m) , pow2[0] = 1 ;
        for(int i=1;i<=m;++i) pow2[i] = pow2[i-1]*2 ;
        for(int nc=1;nc<=n;++nc){
            memset(f,-1,sizeof(f)) ;
            for(int i=1;i<=m;++i) read(val[i]) ;
            ans += dp(1,m) ;
        }
        pput(ans) ;
    }
    
  • 相关阅读:
    ASP.Net 反射显示
    ASP.Net 反射简单工厂模式
    ASP.Net MVC生成验证码
    ASP.Net EF架构
    ASP.Net 邮箱发送
    ASP.Net 反射简单
    ASP.Net 显示
    新年快乐
    测试开发比
    Linkbot介绍
  • 原文地址:https://www.cnblogs.com/tyqtyq/p/10420687.html
Copyright © 2020-2023  润新知