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 ...
随机推荐
- hibernate 的SessionFactory的getCurrentSession 与 openSession() 的区别
1 getCurrentSession创建的session会和绑定到当前线程,而openSession不会. 2 getCurrentSession创建的线程会在事务回滚或事物提交后自动关闭,而ope ...
- Openfire3.9.3源代码导入eclipse中开发配置指南
这篇文章向大家介绍一下,如何把openfire3.9.3源码导入eclipse中,编译并启动的详细过程. 首先得感谢这篇文章的作者,http://www.micmiu.com/opensource/o ...
- Hadoop_UDTF示例
UDTF: 一进多出 UDTF(User-Defined Table-Generating Function)支持一个输入多个输出, 一般用于解析工作,比如说解析url,然后获取url中的信息 编码: ...
- C# 依赖注入
http://www.cnblogs.com/leoo2sk/archive/2009/06/17/1504693.html 这篇文章真的非常非常好···绝对值得收藏学习. 目录 目录 1 ...
- 20145220&20145209&20145309信息安全系统设计基础实验报告(3)
20145220&20145209&20145309信息安全系统设计基础实验报告(3) 实验报告链接: http://www.cnblogs.com/zym0728/p/6132243 ...
- System.Linq.Dynamic的使用
项目中经常用到组合条件查询,根据用户配置的查询条件进行搜索,拼接SQL容易造成SQL注入,普通的LINQ可以用表达式树来完成,但也比较麻烦.有个System.Linq.Dynamic用起来比较方便. ...
- iOS相关笔记
#协议[1] [2] @property (nonatomic, assign) id<EveryFrameDelegate> delegate; 表明,这个delegate是一个需要实现 ...
- Android 保存图片到SQLite
[转:原文] Resources res = getResources(); Bitmap bmp = BitmapFactory.decodeResource(res, R.drawable.ico ...
- Windows一些零碎
一.端口被占用: 1.netstat -ano |findstr 80 //查看3306端口是否存在 2.tasklist |findstr 3036(PID号)//查看pid为3036的是什么程序在 ...
- ECharts饼图试玩
处理类似提交问卷的数据,要生成图表,用了ECharts,好方便的. 简陋效果: 1.表单存储 有单选和多选题,单选直接存储各选项数字值,1,2,3,4...中一个:多选用|分隔存储选项值,如1|3,2 ...