zoukankan      html  css  js  c++  java
  • 2014在百度之星程序设计大赛

    小记:dfs暂停,不是决定性的


    思维:由于只有三个方向向上和向下和向右,然后,我对待每列从左至右。然后,当在下一列的上一列的处理再加工每个值去获得正确的值,保存各坐标的数组格你可以得到最大值。每处理完一列就得到了这一列每一个点所能得到的最大值了,每一列依据从上一列某点往右然后上下更新当前列的全部点,时间复杂度O(n*n*m)


    代码:

    #include <iostream>
    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    #include <map>
    #include <set>
    #include <vector>
    #include <stack>
    #include <queue>
    #include <algorithm>
    
    
    using namespace std;
    
    
    #define mst(a,b) memset(a,b,sizeof(a))
    #define eps 10e-8
    
    
    const int MAX_ = 110;
    const int N = 100010;
    const int INF = 0x7fffffff;
    
    
    
    
    //int dir[3][2] = {{0,-1}, {1,0}, {0,1}};
    //bool vis[MAX_][MAX_];
    int mp[MAX_][MAX_];
    int num[MAX_][MAX_];
    int n, m, ans, cs;
    
    
    
    
    void find(int x){
        for(int i = 1; i <= n; ++i){
            int tmp = num[i][x-1] + mp[i][x];
            if(num[i][x] < tmp)num[i][x] = tmp;
            for(int j = i+1; j <= n; ++j){
                tmp += mp[j][x];
                if(tmp > num[j][x])num[j][x] = tmp;
            }
        }
        for(int i = n; i > 0; --i){
            int tmp = num[i][x-1] + mp[i][x];
            if(num[i][x] < tmp)num[i][x] = tmp;
            for(int j = i-1; j > 0; --j){
                tmp += mp[j][x];
                if(tmp > num[j][x])num[j][x] = tmp;
            }
        }
    }
    
    
    int main(){
        int T;
        scanf("%d", &T);
        for(int Ca = 1; Ca <= T; ++Ca){
            scanf("%Id%d", &n, &m);
            for(int i = 1; i <= n; ++i){
                for(int j = 1; j <= m; ++j){
                    scanf("%d", &mp[i][j]);
                    num[i][j] = -INF;
                }
            }
            num[1][1] = mp[1][1];
            for(int i = 2; i <= n; ++i){
                num[i][1] = num[i-1][1] + mp[i][1];
            }
            for(int i = 2; i <= m; ++i){
                find(i);
            }
            printf("Case #%d:
    %d
    ",Ca, num[1][m]);
    
    
        }
        return 0;
    }

    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    POJ 3468 A Simple Problem with Integers
    BZOJ 4430 Guessing Camels
    POJ 2309 BST
    POJ 1990 MooFest
    cf 822B Crossword solving
    cf B. Black Square
    cf 828 A. Restaurant Tables
    Codefroces 822C Hacker, pack your bags!
    [HDU 2255] 奔小康赚大钱
    [BZOJ 1735] Muddy Fields
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4737669.html
Copyright © 2011-2022 走看看