zoukankan      html  css  js  c++  java
  • HDU 1081 To The Max

    题意:输入n,然后输入n行n列的矩阵,找出这个矩阵中的子矩阵最大值。

    #include <iostream>
    #include <queue>
    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <stack>
    #include <algorithm>
    
    using namespace std;
    
    const int maxn = 105;
    const int oo = 222;
    
    int a[maxn][maxn];
    
    int main()
    {
        int n;
        int x;
        while(~scanf("%d", &n))
        {
            for(int i=1; i<=n; i++)
            {
                for(int j=1; j<=n; j++)
                {
                    scanf("%d", &x);
                    a[i][j] = a[i][j-1]+x;
                }
            }
            int Max = a[1][1];
            int sum;
            for(int i=1; i<=n; i++)//枚举列的数目
            {
                for(int j=i; j<=n; j++)//从第j列开始
                {
                    sum = 0;
                    for(int k=1; k<=n; k++)//枚举连续行
                    {
                        sum+=a[k][j]-a[k][j-i];//找出连续行连续列的最大值,即子矩阵的最大值
                        if(sum<0)
                            sum = 0;
                        if(sum>Max)
                            Max = sum;
                    }
                }
            }
    
            printf("%d
    ", Max);
    
        }
    
        return 0;
    }
  • 相关阅读:
    重排序
    线程的生命周期状态
    并发的有序性
    并发的可见性
    并发的原子性
    Java内存模型
    缓存一致性协议MESI
    lsof
    nmap
    elastcisearch简介
  • 原文地址:https://www.cnblogs.com/mengzhong/p/5443427.html
Copyright © 2011-2022 走看看