全部评论 1

  • 可以更优化:

    
    #include<cstdio>
    
    #define maxof(a,b) ((a)>(b)?(a):(b))
    
    struct node{
        int a,b,c;
        node(int _a=0,int _b=0,int _c=0) 
        noexcept: a(_a),b(_b),c(_c){}
        void assign(const node& that) noexcept{*this=that;}
    };
    
    int main(void){
        
        int n;
        std::fscanf(stdin,"%d",&n);
        
        node dp;
        while(n--){
    
            short a,b,c;
            std::fscanf(stdin,"%hd%hd%hd",&a,&b,&c);
            
            node t( \
                maxof(dp.b,dp.c)+a, \
                maxof(dp.a,dp.c)+b, \
                maxof(dp.a,dp.b)+c \
            );
            dp.assign(t);
        }
    
        std::fprintf(stdout,"%d",maxof(maxof(dp.a,dp.b),dp.c));
    }
    

    2026-07-28 来自 广东

    0
暂无数据

提交答案之后,这里将显示提交结果~

首页