To the Max
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 48232   Accepted: 25534

Description

Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous sub-array of size 1*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. 

Input

The input consists of an N * 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.

Sample Input

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

Sample Output

15

给一个矩阵,求其子矩阵所有元素加和的最大值。。。

没想到n^4的复杂度能过。。。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 105
#define INF 999999999 int num[N][N];
int dpUL[N][N];
int main()
{
int n;
scanf("%d",&n);
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
scanf("%d",&num[i][j]);
int res=-INF;
for(int i=; i<=n; i++)
for(int j=; j<=n; j++)
{
dpUL[i][j]=dpUL[i-][j]+dpUL[i][j-]-dpUL[i-][j-]+num[i][j];
res=max(res,dpUL[i][j]);
for(int r=; r<i; r++)
{
for(int c=; c<j; c++)
res=max(res,dpUL[i][j]-dpUL[i][c]-dpUL[r][j]+dpUL[r][c]);
}
}
printf("%d\n",res);
return ;
}
/*
-1 -1 -1 -1
-1 2 2 -1
-1 2 2 -1
-1 -1 -1 -1
*/
												

POJ_1050_(dp)的更多相关文章

  1. BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 4142  Solved: 1964[Submit][Statu ...

  2. 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...

  3. AEAI DP V3.7.0 发布,开源综合应用开发平台

    1  升级说明 AEAI DP 3.7版本是AEAI DP一个里程碑版本,基于JDK1.7开发,在本版本中新增支持Rest服务开发机制(默认支持WebService服务开发机制),且支持WS服务.RS ...

  4. AEAI DP V3.6.0 升级说明,开源综合应用开发平台

    AEAI DP综合应用开发平台是一款扩展开发工具,专门用于开发MIS类的Java Web应用,本次发版的AEAI DP_v3.6.0版本为AEAI DP _v3.5.0版本的升级版本,该产品现已开源并 ...

  5. BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]

    1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4026  Solved: 1473[Submit] ...

  6. [斜率优化DP]【学习笔记】【更新中】

    参考资料: 1.元旦集训的课件已经很好了 http://files.cnblogs.com/files/candy99/dp.pdf 2.http://www.cnblogs.com/MashiroS ...

  7. BZOJ 1010: [HNOI2008]玩具装箱toy [DP 斜率优化]

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9812  Solved: 3978[Submit][St ...

  8. px、dp和sp,这些单位有什么区别?

    DP 这个是最常用但也最难理解的尺寸单位.它与“像素密度”密切相关,所以 首先我们解释一下什么是像素密度.假设有一部手机,屏幕的物理尺寸为1.5英寸x2英寸,屏幕分辨率为240x320,则我们可以计算 ...

  9. android px转换为dip/dp

    /** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) */ public int dipTopx(Context context, float dpValue) { final floa ...

随机推荐

  1. 【动态规划】Dynamic Programming

    动态规划 一.动态规划 动态规划(Dynamic Programming)是一种设计的技巧,是解决多阶段决策过程最优化问题的通用方法. 基本思想:将待求解问题分解成若干个子问题,先求解子问题,然后从这 ...

  2. 字符串匹配之KMP算法(续)---还原next数组

    相信通过今天的文章,你会对KMP的认识更加深入一层,不止停留在知道怎样计算的层面上了,废话不多说,開始. 通过前面的第一篇文章,知道了怎么求next数组,相信非常多喜欢刨根问底的人就会问,我依照你的做 ...

  3. unity3D游戏开发实战原创视频讲座系列13之帽子戏法游戏开发(预告)

    文件夹 第一讲  游戏演示项目创建 第二讲 游戏场景的编辑 第三讲  帽子的移动 第四讲  炮弹的产生 第六讲  游戏界面的完好 第七讲 各种UI的制作 第八讲  分数和爆炸特效   视持续更新中.. ...

  4. XMU 1125 越野车大赛 【三分】

    1125: 越野车大赛 Time Limit: 500 MS  Memory Limit: 64 MB  Special JudgeSubmit: 8  Solved: 4[Submit][Statu ...

  5. commons-fileupload 组件实现文件上传

    index.jsp 核心代码: //创建文件项工厂 DiskFileItemFactory factory = new DiskFileItemFactory(); //创建解析请求 数据的Servl ...

  6. Java日期推迟计算、日期大小

    /** * 日期推迟计算 * @param date * @param num * @return java.util.HashMap<java.lang.String,java.lang.St ...

  7. go语言---for

    go语言---for https://blog.csdn.net/cyk2396/article/details/78873930 执行以下代码,发现无法跳出for循环: func SelectTes ...

  8. 4.8 Using Ambiguous Grammars

    4.8 Using Ambiguous Grammars It is a fact that every ambiguous grammar fails to be LR and thus is no ...

  9. recast 生成navmesh主要流程

    参考:      critterai  http://www.critterai.org      recast & Detour https://github.com/recastnavig ...

  10. bzoj 1572: [Usaco2009 Open]工作安排Job【贪心+堆】

    先按照时间顺序加,价值塞进小根堆里,碰到不合法情况就从堆里减去 #include<iostream> #include<cstdio> #include<queue> ...