zoukankan      html  css  js  c++  java
  • HDU 1024 Max Sum Plus Plus

    好难。。看了kuangbin大神的博客讲解才会。。自己写的时候又写了好久。。。

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    
    const int maxn=1000000+10;
    int a[maxn],b[maxn];
    int c[maxn];
    int x[maxn];
    int n,m;
    
    int main()
    {
        while(~scanf("%d%d",&m,&n))
        {
            for(int i=1; i<=n; i++) scanf("%d",&x[i]);
            for(int i=0; i<=n; i++) b[i]=c[i]=a[i]=-0x7fffffff;
            int ans=-0x7fffffff;
    
            for(int j=1; j<=n; j++)
            {
                for(int i=1; i<=min(m,j); i++)
                {
                    if(j==1) c[i]=x[j];
    
                    else if(i==1)
                    {
                        if(b[i]<0) c[i]=x[j];
                        else c[i]=b[i]+x[j];
                    }
    
                    else c[i]=max(b[i],a[i-1])+x[j];
                    if(i==m) ans=max(ans,c[i]);
                }
                for(int i=1; i<=min(m,j); i++) b[i]=c[i];
                for(int i=1; i<=min(m,j); i++) a[i]=max(a[i],b[i]);
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    第 7 章 Neutron
    第 7 章 Neutron
    第 7 章 Neutron
    第 7 章 Neutron
    第 7 章 Neutron
    第 7 章 Neutron
    第 7 章 Neutron
    第 7 章 Neutron
    第 7 章 Neutron
    iOS 屏幕旋转 nav+tabbar+present(网页) 2016
  • 原文地址:https://www.cnblogs.com/zufezzt/p/5137424.html
Copyright © 2011-2022 走看看