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 ...
随机推荐
- ASIHttpRequest 使用理解
开源库:ASIHttpRequest ASIHttpRequest 下载网址:http://github.com/pokeb/asi-http-request 依赖的5个库文件:CFNetwork, ...
- Python之路第一课Day1--随堂笔记
课堂大纲: 一.Python介绍 二.发展史 三.Python 2 or 3? 四.安装 五.Hello World程序 六.变量 七.用户输入 八.模块初识 九..pyc是个什么鬼? 十.数据类型初 ...
- html()、text()、val()、innerHTML、value()的区分
以上的方法可用于一般的html标签(div)与input中分别进行讨论 1.html(): jQuery方法,用于一般标签中,可读写,可以获得写入html标签. 2.text(): jQuery方法, ...
- 第 1 章 jQuery 入门
学习要点: 1.什么是 jQuery 2.学习 jQuery 的条件 3.jQuery 的版本 4.jQuery 的功能和优势 5.其他 JavaScript 库 6.是否兼容低版本 IE 7.下载及 ...
- HDU5769 Substring(后缀数组)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5769 #include <iostream> #include <stdio.h> ...
- github搭建静态博客
p { margin-bottom: 0.1in; line-height: 120% } 1. 创建Repository 创建一个与自己github用户名对应的Repository,例如:abc.g ...
- [计算机故障]windows8+IE11显示无法登陆网页
同事的一款SURFACE,跑的WINDOWS 8.1.最近发现从开始菜单里的win8.1的浏览器可以上网,但是通过任务栏的快捷方式,又上不了网.尝试重置了IE11,安装了Google Chrome.但 ...
- “菜”鸟理解.NET Framework(CLI,CLR,CTS,CLS,BCL,FCL)
既然要学.NET,就要先认识认识她,我不喜欢大段大段文字的东西,自己通过理解,画个图,来看看.NET的沉鱼落雁,闭月羞花之容. 最下层蓝色部分是.NET Framework的基础,也是所有应用软件的基 ...
- git SourceTree常用操作
1.git 修改用户名以及提交邮箱 修改用户名和邮箱有两种方式,第一种 git 修改当前的project的用户名的命令为:git config user.name 你的目标用户名; git 修改当前 ...
- VSCODE 插件初探
写在前面 分享一个vscode插件background(用于改变背景).点击直接跳到vscode插件开发步骤 做vscode的插件,很久就有这个想法了,但是一直因为这样,那样的事情耽误,放弃了N次.不 ...