zoukankan      html  css  js  c++  java
  • Comb CodeForces

    题面
    Having endured all the hardships, Lara Croft finally found herself in a room with treasures. To her surprise she didn't find golden mountains there. Lara looked around and noticed on the floor a painted table n × m panels in size with integers written on the panels.
    题意
    在一个(n * m)的矩阵中,第(i)取前(c_i)个元素,要求(c1 > c2 < c3 > c4 < ...) 求最后取到的元素和的最大值.
    思路
    (dp[i][j]) 表示第(i)行取(j)个元素的最大值.
    在奇数行和偶数行按不同的顺序更新就行了.

    #include<iostream>
    #include<algorithm>
    #include<vector>
    #include<stack>
    #include<queue>
    #include<map>
    #include<set>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<ctime>
    
    #define fuck(x) cerr<<#x<<" = "<<x<<endl;
    #define debug(a, x) cerr<<#a<<"["<<x<<"] = "<<a[x]<<endl;
    #define lson l,mid,ls
    #define rson mid+1,r,rs
    #define ls (rt<<1)
    #define rs ((rt<<1)|1)
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    const int loveisblue = 486;
    const int maxn = 1689;
    const int maxm = 100086;
    const int inf = 0x3f3f3f3f;
    const ll Inf = 999999999999999999;
    const int mod = 1000000007;
    const double eps = 1e-6;
    const double pi = acos(-1);
    
    ll dp[maxn][maxn];
    ll num[maxn][maxn];
    ll sum[maxn];
    int main() {
        ios::sync_with_stdio(true);
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
    #endif
    
        int n,m;
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                scanf("%lld",&num[i][j]);
            }
        }
        ll ans = -Inf;
        for(int i=1;i<=n;i++){
            if(i&1){
                ll mx = -Inf;
                for(int j=1;j<=m;j++){
                    sum[j]=sum[j-1]+num[i][j];
    
                    dp[i][j]=mx+sum[j];
    
                    mx = max(mx,dp[i-1][j]);
                }
    
            }else{
                ll mx=-Inf;
                for(int j=1;j<=m;j++){
                    sum[j]=sum[j-1]+num[i][j];
                }
                for(int j=m;j>=1;j--){
                    dp[i][j]=mx+sum[j];
                    mx = max(mx,dp[i-1][j]);
                }
    
            }
        }
        for(int i=n;i<=n;i++){
            for(int j=1;j<=m;j++){
                ans=max(ans,dp[i][j]);
    //            cout<<dp[i][j]<< " ";
            }
    //        cout<<endl;
    
        }
        printf("%lld
    ",ans);
    
        return 0;
    }
    
  • 相关阅读:
    Mac zsh: command not found zsh 所有命令在终端失效
    Java根据FreeMarker模板生成Word(doc)文档(带图片)
    2021年Java面试总结——自我篇
    toArray转换踩坑 java.lang.ClassCastException
    并发和并行
    protoBuf3学习
    StringBuffer和StringBuilder区别
    深拷贝和浅拷贝
    从不订购的客户
    使用jenkins遇到的问题汇总
  • 原文地址:https://www.cnblogs.com/ZGQblogs/p/11512057.html
Copyright © 2011-2022 走看看