To the Max
--------------------------------------------------------------------------------
Time Limit: 1 Second      Memory Limit: 32768 KB
--------------------------------------------------------------------------------
Problem
Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1 x 1 or greater located within the whole array. The sum of a rectangle is the sum of all the elements in that rectangle. In this problem the sub-rectangle with the largest sum is referred to as the maximal sub-rectangle.
As an example, the maximal sub-rectangle of the array:

0 -2 -7 0
9 2 -6 2
-4 1 -4 1
-1 8 0 -2

is in the lower left corner:

9 2
-4 1
-1 8

and has a sum of 15.
The input consists of an N x N array of integers. The input begins with a single positive integer N on a line by itself, indicating the size of the square two-dimensional array. This is followed by N 2 integers separated by whitespace (spaces and newlines). These are the N 2 integers of the array, presented in row-major order. That is, all numbers in the first row, left to right, then all numbers in the second row, left to right, etc. N may be as large as 100. The numbers in the array will be in the range [-127,127].

Output
  Output the sum of the maximal sub-rectangle.

Example Input
4
0 -2 -7 0 9 2 -6 2
-4 1 -4 1 -1
8 0 -2
Output
15

 #include<stdio.h>
#include<string.h>
#define MAXN 105
int main()
{
//freopen("a.txt","r",stdin);
int i,j,k,n,t,sum,max;
int a[MAXN][MAXN];
while (scanf("%d",&n)!=EOF)
{
memset(a,,sizeof(a));
for (i=;i<=n;++i)
{
for (j=;j<=n;++j)
{
scanf("%d",&t);
a[i][j]=a[i-][j]+t;
}
}
max=;
for (i=;i<=n;++i)
{
for (j=i;j<=n;++j)
{
sum=;
for (k=;k<=n;++k)
{
t=a[j][k]-a[i-][k];
sum+=t;
if (sum<) sum=;
if (sum>max) max=sum;
}
}
}
printf("%d\n",max);
}
return ;
}

AC

To the Max的更多相关文章

  1. Kafka副本管理—— 为何去掉replica.lag.max.messages参数

    今天查看Kafka 0.10.0的官方文档,发现了这样一句话:Configuration parameter replica.lag.max.messages was removed. Partiti ...

  2. 排序算法----基数排序(RadixSort(L,max))单链表版本

    转载http://blog.csdn.net/Shayabean_/article/details/44885917博客 先说说基数排序的思想: 基数排序是非比较型的排序算法,其原理是将整数按位数切割 ...

  3. [LeetCode] Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K

    Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...

  4. [LeetCode] Max Points on a Line 共线点个数

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

  5. BZOJ 4390: [Usaco2015 dec]Max Flow

    4390: [Usaco2015 dec]Max Flow Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 177  Solved: 113[Submi ...

  6. supervisor监管进程max file descriptor配置不生效的问题

    配置了 sudo vim /etc/security/limits.conf * soft nofile * hard nofile   单独起进程没问题, 放到supervisor下监管启动,则报错 ...

  7. Max double slice sum 的解法

    1. 上题目: Task description A non-empty zero-indexed array A consisting of N integers is given. A tripl ...

  8. 3ds max 渲染清晰面片的边缘

    3ds max的菜单栏 -> 渲染 -> 材质编辑器->精简材质编辑器,将面状打勾,如下图,就能渲染出面片清晰的图形.

  9. sql中NVARCHAR(MAX) 性能和占空间分析 varchar(n),nvarchar(n) 长度性能及所占空间分析

    varchar(n),nvarchar(n) 中的n怎么解释: nvarchar(n)最多能存n个字符,不区分中英文. varchar(n)最多能存n个字节,一个中文是两个字节. 所占空间: nvar ...

  10. find out the neighbouring max D_value by counting sort in stack

    #include <stdio.h> #include <malloc.h> #define MAX_STACK 10 ; // define the node of stac ...

随机推荐

  1. Common Lisp编译程序的小技巧

    这几天开始玩Common Lisp,遇上了一个有意思的问题,CL一般是解释运行,也有实现可以编译生成字节码(fas文件).我正在用的两种CL实现是SBCL和CLISP,前者是我从<实用Commo ...

  2. 第一个C语言编译器是怎样编写的?

    首先向C语言之父Dennis MacAlistair Ritchie致敬! 当今几乎所有的实用的编译器/解释器(以下统称编译器)都是用C语言编写的,有一些语言比如Clojure,Jython等是基于J ...

  3. 九幽史程博:助力国内开发者借Win10东风出海

    微软Biuld2016大会刚刚结束,会议上微软CEO纳德拉Show出的一大波黑科技,又一次让软粉们心情为之振奋,信仰充值爆棚! 尽管过去一年微软的Win10 Mobile表现不尽如人意,可是凭借PC端 ...

  4. xcode更新,想想也是醉了

    每次更新,都要整个文件全部更新,这下载速度,想想也是醉了,苹果你就不能搞了更新包吗!!

  5. 最新app store 应用提交经验分享

    由于之前提交实在3月份的时候,后来长时间没有提交了,最近又需要提交,发现苹果已经发生翻天覆地的变化了,真是跟不上时代了啊.... 之前提交的基本也是从网上看的,前面的证书安装部分其实基本是一样的没什么 ...

  6. [USACO2003][poj2138]Travel Games(dp/最长路)

    http://poj.org/problem?id=2138 题意:给你一些单词和初始单词,在初始单词的任意位置你可以加任意一个字母,使得这个新单词在给的单词中有所出现,然后在这样不断迭代下去,让你求 ...

  7. 第十四章 校本化CSS

    CSS(层叠样式表)是一种指定HTML文档视觉的表现的标准.CSS本来是让视觉设计师来使用的:它允许设计师精确的对文档元素的字体 ,颜色,外边距,缩进,边框甚至是定位.不过,客户端javascript ...

  8. MongoDB学习与BUG解答

    简单介绍: MongoDb也是NoSQL中的一种,并且是应用比较火的一门解决高效处理数据的技术. 网上说它是介于关系数据库 和非关系数据库之间的产品,它是非关系数据库中最丰富的,最像关系数据的. Q: ...

  9. 小记:Quartz StartNow() 无效

    今天遇到一个问题,调度器在启动时无法立刻开始执行任务,代码如下: var trigger = TriggerBuilder.Create() .StartNow() //此处无效 .WithCronS ...

  10. 英语etc怎么发音、单词来历

    etc是等等的意思,与and so on 相同 音标/et'set(a)ra/ 源于法语et cetera,也是等等的意思 在计算机操作系统目录(linux和windows)有一个叫etc的目录 里面 ...