【poj1050】 To the Max
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的更多相关文章
- 【转】有效修改max open files/ulimit -n
[转]有效修改max open files/ulimit -n_追梦20121222_新浪博客 [转]有效修改max open files/ulimit -n (2011-11-18 0 ...
- 010-elasticsearch5.4.3【四】-聚合操作【一】-度量聚合【metrics】-min、max、sum、avg、count
一.概述 度量类型聚合主要针对的number类型的数据,需要ES做比较多的计算工作 参考向导:地址 import org.elasticsearch.search.aggregations.Aggre ...
- 【 HDU1081 】 To The Max (最大子矩阵和)
题目链接 Problem - 1081 题意 Given a two-dimensional array of positive and negative integers, a sub-rectan ...
- 【转载】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 ...
- 【HDOJ-1081】To The Max(动态规划)
To the Max Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem ...
- 【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 ...
- 【动态规划】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 ...
- 【Unity】3.4 将现有的3ds Max模型导入到Unity
分类:Unity.C#.VS2015 创建日期:2016-04-05 一.简介 这一节我们用一个带有"装子弹和上膛"动画的"枪"模型,介绍在3ds Max 20 ...
- 【Unity】3.3 用3ds Max 2015制作模型并将其导入到Unity
分类:Unity.C#.VS2015 创建日期:2016-04-05 一.常用三维软件简介 由于游戏引擎本身的建模功能相对较弱,无论是专业性还是自由度都无法同专业的三维软件相比,所以大多数游戏中的模型 ...
随机推荐
- Android数据存储(二)----PreferenceFragment详解
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...
- css中position属性(absolute|relative|static|fixed)概述及应用
position属性的相关定义: static:无特殊定位,对象遵循正常文档流; relative:对象遵循正常文档流; absolute:对象脱离正常文档流 fixed:对象脱离正常文档流 我们先来 ...
- AutoIT 实现Firefox上传文件
Firefox浏览器文件上传代码如下: ;upload file Func _UploadFile($file) AutoItSetOption("WinTitleMatchMode&quo ...
- jquery的children方法和css3选择器配合使用
$(".pid").children("ul:nth-child(2)");//获取拥有pid类元素下的第二个ul元素 $(".pid"). ...
- jquery中$("#afui").get(0)为什么要加get(0)呢?
jquery中$("#afui").get(0)为什么要加get(0)呢? 2015-04-13 17:46SYYZZ3 | 浏览 509 次 Jquery $("#a ...
- nodejs 针对 mysql 设计的原型库,支持事务/共享多次/单次查询
//通过this访问内置流程对象, 在每个流程中都能使用 //this.conn => mysql-connection //this.results => 整个流程数已经返回的值 //t ...
- JS实现点击跳转登陆邮箱
前言 注册的过程中往往需要填写邮箱,并登陆邮箱进行验证.利用JS可以实现针对不同的邮箱进行点击登录验证,以下为实现方案,很简单 代码 邮箱域名数据 1 2 3 4 5 6 7 8 9 10 11 ...
- MemCached配置与缓存知识概述
先看看百度百科里面对缓存的介绍: 缓存(Cache memory)是硬盘控制器上的一块内存芯片,具有极快的存取速度,它是硬盘内部存储和外界接口之间的缓冲器.由于硬盘的内部数据传输速度和外界介面传输速度 ...
- Arduino智能小车制作报告
Arduino智能小车制作报告 制作成员:20135224陈实 20135208贺邦 20135207王国伊 前提: Arduino,是一个开源的单板机控制器,采用了基于开放源代码的软硬件平台,构 ...
- 20135316王剑桥 linux第二周课实验笔记
Linux中命令格式为: command [options选项] [arguments参数] //中括号代表是可选的,即有些命令不需要选项也不需要参数 ls或ls .显示是当前目录的内容,这里“.”就 ...