【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配置----小米手机通过wifi连接ADB调试Android应用
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/3 ...
- java 21 - 8 复制文本文件的5种方式
需求:复制文本文件 分析: 由于文本文件我们用记事本打开后可以读懂,所以使用字符流. 而字符流有5种复制的方式: 首先写main方法 public static void main(String[] ...
- android strings.xml 报 is not translated in af,
57 down vote In your ADT go to window->Preferences->Android->Lint Error Checking Find there ...
- Volley(三)—— ImageRequest & Request简介
Volley(三)—— ImageRequest & Request简介 上 篇文章我们讲 到了如何用volley进行简单的网络请求,我们可以很容易的接受到string.JsonObjec类型 ...
- easyui添加自定义验证规则
$.extend($.fn.validatebox.defaults.rules, { phone: { validator: function (value) { return /^(\d{3,4} ...
- Python进阶-面向对象
类的成员 类的成员可以分为三类:字段.方法.属性 一:字段: 普通字段和静态字段,他们在定义和使用中有所区别,而最本质的区别是内存中保存的位置不同 普通字段属于对象 静态字段属于类 字段的定义和使用 ...
- msg url
- 【转】【C#】SendMessage
SendMessage是一个在user32.dll中声明的API函数,在C#中导入如下: using System.Runtime.InteropServices; [DllImport(" ...
- drbd初探及Heartbeat+DRBD+MySQL
1,drbd快速入门 http://www.mingxiao.info/article/?id=39#__RefHeading___Toc1114_501652171 2.Heartbeat+DRBD ...
- python数字图像处理(3):图像像素的访问与裁剪
图片读入程序中后,是以numpy数组存在的.因此对numpy数组的一切功能,对图片也适用.对数组元素的访问,实际上就是对图片像素点的访问. 彩色图片访问方式为: img[i,j,c] i表示图片的行数 ...