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)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8839    Accepted Submission(s):
4281
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 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].
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int dp[];
int num[][]; int main ()
{
int n;
while (~scanf("%d",&n))
{
for (int i=; i<n; i++)
for (int j=; j<n; j++)
scanf("%d",&num[i][j]);
int ans=-;
for (int i=; i<n; i++)
{
memset(dp,,sizeof(dp));
for (int j=i; j<n; j++)
{
int Max=-;
for (int k=; k<n; k++)
{
dp[k]+=num[j][k]; //先计算出所有的dp和
}
for (int k=; k<n; k++) //1003的做法,代码类似
{
if (Max+dp[k]<dp[k])
Max=dp[k];
else
Max=Max+dp[k];
if (ans<Max) //不断更新最大值
{
ans=Max;
//cout<<j<<" "<<k<<endl;
}
}
}
}
printf ("%d\n",ans);
}
return ;
}
hdu 1081 To The Max(dp+化二维为一维)的更多相关文章
- URAL 1146 Maximum Sum & HDU 1081 To The Max  (DP)
		
点我看题目 题意 : 给你一个n*n的矩阵,让你找一个子矩阵要求和最大. 思路 : 这个题都看了好多天了,一直不会做,今天娅楠美女给讲了,要转化成一维的,也就是说每一列存的是前几列的和,也就是说 0 ...
 - HDU 1081 To The Max【dp,思维】
		
HDU 1081 题意:给定二维矩阵,求数组的子矩阵的元素和最大是多少. 题解:这个相当于求最大连续子序列和的加强版,把一维变成了二维. 先看看一维怎么办的: int getsum() { ; int ...
 - 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 ...
 - Max Sum Plus Plus HDU - 1024      基础dp   二维变一维的过程,有点难想
		
/* dp[i][j]=max(dp[i][j-1]+a[j],max(dp[i-1][k])+a[j]) (0<k<j) dp[i][j-1]+a[j]表示的是前j-1分成i组,第j个必 ...
 - HDU 1081 To the Max 最大子矩阵(动态规划求最大连续子序列和)
		
Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...
 - 经典DP 二维换一维
		
HDU 1024 Max Sum Plus Plus // dp[i][j] = max(dp[i][j-1], dp[i-1][t]) + num[j] // pre[j-1] 存放dp[i-1] ...
 - 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 ...
 - Hdu 1081 To The Max
		
To The Max Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
 
随机推荐
- 【week2】燃尽图
			
燃尽图(burn down chart)是在项目完成之前,对需要完成的工作的一种可视化表示.燃尽图有一个Y轴(工作)和X轴(时间).理想情况下,该图表是一个向下的曲线,随着剩余工作的完成,“烧尽”至零 ...
 - RT-thread内核之系统时钟
			
一.系统时钟 rt-thread的系统时钟模块采用全局变量rt_tick作为系统时钟节拍,该变量在系统时钟中断函数中不断加1.而系统时钟中断源和中断间隔一般由MCU硬件定时器(如stm32的嘀嗒定时器 ...
 - BZOJ 口胡记录
			
最近实在是懒的不想打代码...好像口胡也算一种训练,那就口胡把. BZOJ 2243 染色(树链剖分) 首先树链剖分,然后记录下每个区间的左右端点颜色和当前区间的颜色段.再对每个节点维护一个tag标记 ...
 - poj1474  Video Surveillance
			
题意:求多边形的内核,即:在多边形内部找到某个点,使得从这个点能不受阻碍地看到多边形的所有位置. 只要能看到所有的边,就能看到所有的位置.那么如果我们能够在多边形的内部的点x看到某条边AB,这个点x一 ...
 - ZOJ3229:Shoot the Bullet——题解
			
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3229 题目大意:射命丸文要给幻想乡的居民照相,共照n天m个人,每天射命丸文 ...
 - 分享几款常用的API/文档浏览器
			
1.Dash 支持平台:Mac iOS 官网:https://kapeli.com/dash 2.Zeal 支持平台:Linux Windows 官网:https://zealdocs.org/ G ...
 - NOIP2017金秋冲刺训练营杯联赛模拟大奖赛第一轮Day2题解
			
上星期打的...题有点水,好多人都AK了 T1排个序贪心就好了 #include<iostream> #include<cstring> #include<cstdlib ...
 - [IOI2007]Miners 矿工配餐
			
link 其实就是一个比较简单的$IOI$题.简单$dp$就行,设$5$维$dp$即可 最后在滚动一下,判一下可行性即可. #include<iostream> #include<c ...
 - rand、randi和randn的区别?
			
1,rand 生成均匀分布的伪随机数.分布在(0~1)之间 主要语法:rand(m,n)生成m行n列的均匀分布的伪随机数 rand(m,n,'double')生成指定精度的均匀分布的伪随机数,参数还可 ...
 - HTML学习基本代码
			
HTML的代码比较繁琐,在此记下一些基本的东西,以后自己回来看看 <html> <head> <title>我的人生啊</title> <styl ...