zoukankan      html  css  js  c++  java
  • POJ 1050 To the Max 暴力,基础知识 难度:0

    http://poj.org/problem?id=1050

    设sum[i][j]为从(1,1)到(i,j)的矩形中所有数字之和

    首先处理出sum[i][j],此时左上角为(x1,y1),右下角为(x2,y2)的矩形中所有数字之和就是sum[x2][y2]-sum[x1][y2]-sum[x2][y1]+sum[x1][y1]

    因为n<100,在不需要优化的边上,所以就直接暴力了

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    const int maxn=1e2+2;
    double e[maxn];
    int match[maxn];
    int n,m;
    int sum[maxn][maxn],maz[maxn][maxn];
    int main()
    {
        scanf("%d",&n);
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=n; j++)
            {
                scanf("%d",maz[i]+j);
                sum[i][j]=sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+maz[i][j];
            }
        }
        int ans=-0x7fffffff;
        for(int x1=0;x1<=n;x1++){
            for(int y1=0;y1<=n;y1++){
                for(int x2=x1+1;x2<=n;x2++){
                    for(int y2=y1+1;y2<=n;y2++){
                        ans=max(ans,sum[x2][y2]-sum[x1][y2]-sum[x2][y1]+sum[x1][y1]);
                    }
                }
            }
        }
        printf("%d
    ",ans);
    
        return 0;
    }
  • 相关阅读:
    2101 可达性统计
    POJ1179 Polygon
    POJ1015 Jury Compromise
    读入输出优化
    队列优化dijsktra(SPFA)的玄学优化
    5104 I-country
    CH5102 Mobile Service
    P1005 矩阵取数游戏
    (模板)线段树2
    POJ3666 Making the Grade
  • 原文地址:https://www.cnblogs.com/xuesu/p/4479731.html
Copyright © 2011-2022 走看看