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;
    }
    
  • 相关阅读:
    Symfony2 学习笔记之报错
    Symfony2学习笔记之数据校验
    Symfony2学习笔记之HTTP Cache
    Symfony2学习笔记之表单
    Symfony2 学习笔记之插件格式
    Symfony2学习笔记之数据库操作
    Symfony2 学习笔记之内部构件
    Symfony2 学习笔记之模板使用
    让VIEWSTATE从页面中完全消失(小技巧)
    打包bat等文件成exe,双击运行不显示dos窗口,exe不报毒
  • 原文地址:https://www.cnblogs.com/ZGQblogs/p/11512057.html
Copyright © 2011-2022 走看看