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. error C2065: “IDD_DIALOG1” : 未声明的标识符

    编译时提示error C2065: “IDD_DIALOG1” : 未声明的标识符 错误的可能原因及解决方法如下: 1.出错文件中没有包含资源文件ID声明的resource.h文件.在出错文件中加入# ...

  2. 疯狂位图之——位图生成12GB无重复随机乱序大整数集

    上一篇讲述了用位图实现无重复数据的排序,排序算法一下就写好了,想弄个大点数据测试一下,因为小数据在内存中快排已经很快. 一.生成的数据集要求 1.数据为0--2147483647(2^31-1)范围内 ...

  3. 通俗易懂------this指向

    因为JavaScript 中this 是在运行期进行绑定的,因此JavaScript 中this 关键字具备多重含义. 具体在实际应用中,this的指向大致可以分为下面4种. 作为对象的方法调用   ...

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

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

  5. Servlet学习 (HttpServletRequest HttpServletResponse)

    1.什么事servlet? 答:服务器端程序, 自定义的服务类型.tomcat是一个容器,这个容器提供各种菜的服务, 我们需要为里面放菜! web服务器就是我们的开发环境和开发基础. 实现了servl ...

  6. Linux安装卸载JDK(1.7 rpm)

    一.卸载系统已有的JDK 1.查看已安装的jdk rpm -qa|grep jdk   2.卸载jdk rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.66. ...

  7. Cellphone Typing 字典树

    Cellphone Typing Time Limit: 5000ms Memory Limit: 131072KB   This problem will be judged on UVA. Ori ...

  8. 解决vs2015使用fopen、fprintf等函数报错的问题

    出现错误提示: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable ...

  9. BZOJ-1880 Elaxia的路线 SPFA+枚举

    1880: [Sdoi2009]Elaxia的路线 Time Limit: 4 Sec Memory Limit: 64 MB Submit: 921 Solved: 354 [Submit][Sta ...

  10. BZOJ-4300 绝世好(蛋疼)题 DP(递推)

    翻zky学长的blog时翻出来的..... 4300: 绝世好题 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 736 Solved: 393 [Sub ...