Hdu 1081 To The Max
To The Max
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7620 Accepted Submission(s): 3692
Problem Description
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.
Input
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
Sample Input
8 0 -2
Sample Output
#include <iostream>
#include <cstdio>
using namespace std;
#define N 105
int arr[N][N],b[N];
int dp(int *a,int m) //求一维数组的最大子段和
{
int i,sum,max;
sum = 0;
max = 0;
for(i=0; i<N; i++)
{
sum += a[i];
if(sum<0)
sum = 0;
if(sum>max)
max = sum;
}
return max;
}
int main()
{
int i,j,k,n,sum,max;
while(scanf("%d",&n)!=EOF)
{
for(i=0; i<n; i++)
for(j=0; j<n; j++)
scanf("%d",&arr[i][j]);
max = 0;
for(i=0; i<n; i++)
{
memset(b,0,sizeof(b));
for(j=i; j<n; j++)
{
for(k=0; k<n; k++)
b[k] += arr[j][k];
sum = dp(b,n);
if(sum>max)
max = sum;
}
}
printf("%d\n",max);
}
return 0;
}
Hdu 1081 To The Max的更多相关文章
- hdu 1081 To The Max(dp+化二维为一维)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1081 To The Max Time Limit: 2000/1000 MS (Java/Others ...
- HDU 1081 To The Max【dp,思维】
HDU 1081 题意:给定二维矩阵,求数组的子矩阵的元素和最大是多少. 题解:这个相当于求最大连续子序列和的加强版,把一维变成了二维. 先看看一维怎么办的: int getsum() { ; int ...
- dp - 最大子矩阵和 - HDU 1081 To The Max
To The Max Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=1081 Mean: 求N*N数字矩阵的最大子矩阵和. ana ...
- URAL 1146 Maximum Sum & HDU 1081 To The Max (DP)
点我看题目 题意 : 给你一个n*n的矩阵,让你找一个子矩阵要求和最大. 思路 : 这个题都看了好多天了,一直不会做,今天娅楠美女给讲了,要转化成一维的,也就是说每一列存的是前几列的和,也就是说 0 ...
- HDU 1081 To The Max(动态规划)
题目链接 Problem Description Given a two-dimensional array of positive and negative integers, a sub-rect ...
- ACM HDU 1081 To The Max
To The Max Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- hdu 1081 To The Max(二维压缩的最大连续序列)(最大矩阵和)
Problem Description Given a two-dimensional array of positive and negative integers, a sub-rectangle ...
- HDU 1081 To The Max (dp)
题目链接 Problem Description Given a two-dimensional array of positive and negative integers, a sub-rect ...
- HDU 1081 To the Max 最大子矩阵(动态规划求最大连续子序列和)
Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...
随机推荐
- sql ce4 的问题
前面用sql ce4来做数据库,发现一个问题.在localhos:xxx下面速度很快,但是一放到iis上面,速度变慢了.每个查询要13秒.分析了好久,最后,查找了半天的资料,去掉了数据库的密码.速度快 ...
- 设置 tableview 的背景颜色,总是有蒙层
1.给tableview添加了背景图片后, cell 总是有一层蒙层蒙着,很阴暗. 2.实验以后才发现背景图片被放在了 cell 的后面.
- SPX Instant Screen Capture
Today I will recommend a NICE screen capture tool, which name is SPA Instant Screen Capture. http:// ...
- 浅谈WebLogic和Tomcat
J2ee开发主要是浏览器和服务器进行交互的一种结构.逻辑都是在后台进行处理,然后再把结果传输回给浏览器.可以看出服务器在这种架构是非常重要的. 这几天接触到两种Java的web服务器,做项目用的Tom ...
- <meta>指定浏览器模式(browser mode)或文档模式(document mode)无效
这是前两天解决的一个故障,准确的说它不是一个SharePoint的问题,而是IE8浏览器或者说是HTML代码的问题,但我感觉还是挺有意思的,所以贴上来分享一下. 基础知识 简单的讲,就是IE浏览器中有 ...
- JQuery控制滚动条滚动到指定位置
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- [工具分享]JetBrains ReSharper 9.0 正式版和注册码
话不多说.直接上百度云盘分享链接.有需要的盆友去下载吧. 百度云盘:http://pan.baidu.com/s/1kTKIQhh 注册码这里提供一个.有需要的自己拿走.或者可以使用压缩包里面的key ...
- jvm性能监控与故障处理工具
jdk为我们提供了一系列的jvm性能监控和故障处理工具,在这里根据学习进度进行整理记录.便于之后查阅 1.jps 虚拟机进程工具 类似于Linux系统中的ps命令,用于查看虚拟机进程,常用的有以下功 ...
- java 默认修饰符
public的类.类属变量及方法,包内及包外的任何类均可以访问:protected的类.类属变量及方法,包内的任何类,及包外的那些继承了此类的子类才能访问:private的类.类属变量及方法,包内包外 ...
- Python开发【前端】:JavaScript
JavaScript入门 JavaScript一种直译式脚本语言,是一种动态类型.弱类型.基于原型的语言,内置支持类型.它的解释器被称为JavaScript引擎,为浏览器的一部分,广泛用于客户端的脚本 ...