http://poj.org/problem?id=1050 (题目链接)

题意

  求二维最大子矩阵

Solution

  数据好像很水,N最大才100,N^4大暴力都可以随便水过。

  其实有N^3的做法。枚举矩阵上下边界,然后把中间的一大坨看作是一维的一条直线,O(n)的做最长子段和即可。当然记得要预处理出前缀和。

代码

// poj1050
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define inf 2147483640
#define Pi 3.1415926535898
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std; int n,a[1010][1010],sum[1010][1010]; int main() {
scanf("%d",&n);
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++) scanf("%d",&a[i][j]),sum[i][j]=a[i][j]+sum[i][j-1];
int ans=-inf;
for (int i=1;i<=n;i++)
for (int j=i;j<=n;j++) {
int s=0;
for (int k=1;k<=n;k++) {
s+=sum[k][j]-sum[k][i-1];
if (s<0) s=0;
else ans=max(ans,s);
}
}
printf("%d",ans);
return 0;
}

  

【poj1050】 To the Max的更多相关文章

  1. 【转】有效修改max open files/ulimit -n

    [转]有效修改max open files/ulimit -n_追梦20121222_新浪博客     [转]有效修改max open files/ulimit -n    (2011-11-18 0 ...

  2. 010-elasticsearch5.4.3【四】-聚合操作【一】-度量聚合【metrics】-min、max、sum、avg、count

    一.概述 度量类型聚合主要针对的number类型的数据,需要ES做比较多的计算工作 参考向导:地址 import org.elasticsearch.search.aggregations.Aggre ...

  3. 【 HDU1081 】 To The Max (最大子矩阵和)

    题目链接 Problem - 1081 题意 Given a two-dimensional array of positive and negative integers, a sub-rectan ...

  4. 【转载】Configure the max limit for concurrent TCP connections

    转载地址:http://smallvoid.com/article/winnt-tcpip-max-limit.html To keep the TCP/IP stack from taking al ...

  5. 【HDOJ-1081】To The Max(动态规划)

    To the Max Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem ...

  6. 【bzoj4390】[Usaco2015 dec]Max Flow LCA

    题目描述 Farmer John has installed a new system of N−1 pipes to transport milk between the N stalls in h ...

  7. 【动态规划】HDU 1081 & XMU 1031 To the Max

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1081 http://acm.xmu.edu.cn/JudgeOnline/problem.php?i ...

  8. 【Unity】3.4 将现有的3ds Max模型导入到Unity

    分类:Unity.C#.VS2015 创建日期:2016-04-05 一.简介 这一节我们用一个带有"装子弹和上膛"动画的"枪"模型,介绍在3ds Max 20 ...

  9. 【Unity】3.3 用3ds Max 2015制作模型并将其导入到Unity

    分类:Unity.C#.VS2015 创建日期:2016-04-05 一.常用三维软件简介 由于游戏引擎本身的建模功能相对较弱,无论是专业性还是自由度都无法同专业的三维软件相比,所以大多数游戏中的模型 ...

随机推荐

  1. NGUI国际化 多语言

    相关组件 NGUI的本地化操作相关的组件 Localization UILocalize Language Selection 主要部分 在需要本地化的UILabel上绑定UILocalize,填写K ...

  2. Android 屏幕适配(二)增强版百分比布局库(percent-support-lib)

    转载请标明出处: http://blog.csdn.net/lmj623565791/article/details/46767825: 本文出自:[张鸿洋的博客] 一 概述 上周一我们发布了Andr ...

  3. VS2013无法启动 IIS Express Web解决办法

    不要勾选[覆盖应用程序根URL(U)],或让[覆盖应用程序根URL(U)]下面的输入框和上面的输入框的地址一样! 使用VS2013有一段时间了,因前期都是编写C/S程序,没有使用到B/S调试器.前几日 ...

  4. CSS选择器的权重与优先规则

    权重顺序 “important > 内联 > ID > 类 > 标签 | 伪类 | 属性选择 > 伪对象 > 继承 > 通配符”.   原文:http://w ...

  5. Gitub

    1.下载地址(注册:jackchn,jackchn@foxmail.com) http://windows.github.com/ 2.使用 github for Windows使用介绍 搭建一个免费 ...

  6. ip routing&no ip routing

    ip routing--------查路由表, 如果ping的目的在RT中没有,不发出任何包(arp也不会发出)   如果RT中存在,则arp  下一跳,相当于no ip routing+配置网关 n ...

  7. C# lambda表达式及初始化器

    using System;using System.Collections.Generic; using System.Linq; namespace ConsoleApplication1d { c ...

  8. JS函数调用的方法

    JS函数调用的四种方法:方法调用模式,函数调用模式,构造器调用模式,apply,call调用模式 1.方法调用模式:先定义一个对象,然后在对象的属性中定义方法,通过myobject.property来 ...

  9. matlab 中的textscan

    textread 与textscan的区别  textscan更适合读入大文件: textscan可以从文件的任何位置开始读入,而textread 只能从文件开头开始读入: textscan也可以从上 ...

  10. [CareerCup] 6.3 Water Jug 水罐问题

    6.3 You have a five-quart jug, a three-quart jug, and an unlimited supply of water (but no measuring ...