POJ 1050 To the Max

poj 1050 poj online judge 1050 最大子矩阵动态规划解决 立即下载

                                          To the Max

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

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

Sample Output

15

题意:给定一个矩阵,找到一个矩阵和最大的子矩阵。

题解:如果是一维数组,那么就是O(N)前缀和扫过去,和小于0后去掉继续扫后面的。该题为二维数组,那么先求出行的前缀和,然后把他们看成一个数组,竖着扫一遍即可。

AC代码:

#include <iostream>
#include <cstring>
using namespace std;
#define _for(i,a,b) for(int i=a;i<=b;i++)
const int maxn = 106;
int n,a[maxn][maxn],sum[maxn][maxn];
int main(int argc, char const *argv[])
{
	cin>>n;
	_for(i,1,n)
	{
		_for(j,1,n)
		{
			cin>>a[i][j];
			sum[i][j]=sum[i][j-1]+a[i][j];
		}
	}
	int ans = 0;
	_for(i,1,n-1)
	{
		_for(k,i+1,n)
		{
			int now = 0;
			_for(j,1,n)
			{
				now+=(sum[j][k]-sum[j][i-1]);	
				ans = max(ans,now);
				if(now<=0)now = 0;
			}			
		}

	}
	cout<<ans<<endl;
	return 0;
}

C++坦克大战源代码 【代码】C++坦克大战源代码。 阅读详情

相关推荐

BUUCTF--[OGeek2019]babyrop

才学习了基本的ROP流程,到处找题练,不过也没做出来几道题,以这道32位的题作为例题吧。 这道题是BUUCTF上pwn练习题里的[OGeek2019]babyrop。 代码审计 老规矩先checksec一下: 没有canary保护,nx保护开启排除shellcode可能性,FULL RELEO为地址随机化。 观察主函数,先设定了一个闹铃,到时间就会强制退出程序,解除闹铃的方法在上一篇博客中提到过了, 这道题中闹铃函数依然对我们解题起不到什么干扰作用。 主函数的思路大概是:生成一个随机数,把这个随机数作为

N1rvana的博客 6009

poj-1050:最大子矩阵(详解:有错求指出)

To the Max POJ - 1050 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 rectang.

m0_52280758的博客 675

POJ1050题解

POJ1050题解 #include <bits/stdc++.h> using namespace std; const int N = 510; int a[N][N], maxrow[N], row[N]; int main() { int n; cin >> n; //读入矩阵数据 for(int i = 0; i < n; i ++ ) for(int j = 0; j < n; j ++ ) cin &g

CK1513710764的博客 1299

COMSOL相场法模拟枝晶生长:溶质偏析模型搭建全流程

凝固过程中枝晶形貌与溶质偏析直接决定铸件微观组织与力学性能,是材料加工领域长期关注的核心问题。相场法凭借弥散界面描述天然处理拓扑演化,成为模拟枝晶生长的主流数值方法,而通用有限元平台COMSOL为自定义偏微分方程求解提供了高度灵活的实现路径。从热力学驱动、界面各向异性到溶质再分配,模型需准确耦合相场方程与浓度扩散方程,才能在二元合金凝固模拟中还原真实枝晶尖端速度、二次臂形貌及界面富集行为。围绕溶质偏析这一关键变量,建模过程涉及无量纲化参数标定、反溶质截留项配置、分离式求解器与网格各向异性控制等核心细节。该方

weixin_30402231的博客 308

NuPlayer 之 Renderer

触发postDrainAudioQueue_l()或postDrainVideoQueue()开始渲染。解码器输出数据 → NuPlayer::Decoder::onMessageReceived。音频数据存入mAudioQueue,视频数据存入mVideoQueue。• 每次写入后通过mNotifyConsumed通知解码器。• 通过AudioSink::write()写入音频设备。• 根据VSync信号和音频时钟调整渲染时机。• 通过Surface直接提交给显示系统。

aningxiaoxixi的博客 313

POJ 1050(贪心,前缀和,区间和)

poj1050 acm 贪心

越看越喜欢啊 2888

2025年北京市职工职业技能大赛第六届信息通信行业网络安全技能大赛复赛CTF部分WP-哥斯拉流量分析

题目没有任何提示,附件gzl.pcap解题哥斯拉流量300多KB包很多,没啥经验只能挨个看回来之后又狠狠得撸了一把哥斯拉流量分析我这里用的是哥斯拉4.0.1测试链接这里发了两个包,我们进行分析。

深耕网络安全领域,聚焦护网行动(HW)、渗透测试、等级保护(等保)、CTF 竞赛四大核心方向,提供技术干货、实战经验与行业洞察。 1812

算法学习之路|poj1050(最大子矩阵和)

题目大意:对于n*n的矩阵,求它的最大子矩阵和。 其实就是最大子串和的扩展版本,当然首先尝试用最大子串和的变体解决这道题。 首先考虑到求矩阵的每一个子矩阵和都可以首先对行或列累加,就把二维矩阵求和转化成一维数组求和。把这一点想办法转化到求最大子串和。 可以初始化时对输入矩阵进行处理,ai表示第i行前j个数字之和。 在计算所有子矩阵的和时,用i,j控制子矩...

weixin_34062329的博客 195

ROS从入门到精通2-1:机器人3D可视化工具——Rviz

本文详细介绍了Rviz是什么?为什么要使用这个工具?清晰地列出了Rviz的安装流程和界面的基本功能元素;讲解了Rviz基本数据类型与话题,并用两个实例深入理解Rviz数据可视化的过程

FRIGIDWINTER的博客 5346

华为OD新系统机试真题 - 配置操作失败数量统计

华为OD机试新系统 4月8号【配置操作失败数量统计】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题【配置操作失败数量统计】。

qq_45776114的博客 1161

poj-1050 题解

题目大意:给定一个N*N的矩阵,求元素和最大的子矩阵,输出该值。   思路:这道题按照常理会计算任意元素为起点的任意大小的子矩阵的和,共有N*(N+1)/2的平方种情况,暴力搜索必定超时。仔细分析可以发现,若某些子矩阵元素计算得到其和为负数,那么就不必考虑包含此子矩阵的其他更大一些的子矩阵。由此想到使用动态规划算法,当从左到右扩展子矩阵大小时,随时记录当前子矩阵的元素和,根据其和的正负来判断是

dragonfly_xp的专栏 664

1. BES2700ZP概述

恒玄BES2700采用RTX5操作系统,配合mindmics算法或者自研算法。

雪飞_海 4470

POJ 1050 To the Max【DP】

做这题前,先弄清楚HDU1003这题。 然后再把二维压缩为一维就可以了。 1,12,123,1234,2,23,234,3,34,4 按上面几种情况压缩,求出最大的即可。

AC_Dreameng 1049

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

POJ1050 To the Max

POJ1050 To the Max 假设最大子矩阵的结果为从第r行到k行、从第i列到j列的子矩阵, 如下所示(ari表示a[r][i],假设数组下标从1开始): | a11 …… a1i ……a1j ……a1n | | a21 …… a2i ……a2j ……a2n | | . . . . | | . . . . | ...

Yoc Lu 349

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

poj1050:to the max

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 rectangl

学习,永不止步 763

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

ACM学习-POJ-1050-To the Max

菜鸟学习ACM,纪录自己成长过程中的点滴。 学习的路上,与君共勉。 ACM学习-POJ-1050-To the Max To the Max Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37462   Accepte

Colin丶 5242

POJ 1050 To the Max【贪心】

To the Max  POJ - 1050  相当于二维的最大子序列,先把他降到一维再贪心或者dp #include #include #include #include #include #include #include #include #include #include #include #include #include #include using na

Puya的博客 371

POJ1050 To the Max 前缀和

题目链接 http://poj.org/problem?id=1050 分析 预处理出每个位置向上各数之和,枚举两行,求在此之间的最大矩形,转化为一维求最大子段和问题。 时间复杂度为 O(n3)O(n ^ 3)O(n3)。 AC代码 #include <cstdio> inline int read() { int num = 0, flag = 1; char c = getc...

Kevin的博客 203

POJ1050 To the Max详解

题目链接 这道题是一道dp 我们首先可以看一下在1维中的情况:最大连续子序列和 #include<cstring> #include<cstdio> using namespace std; int a[105][105]; int n,ans,sum; int main() { freopen("tothemax.in","r",stdin); scanf("...

Robert_6277的博客 600

To the Max POJ - 1050

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...

森宝的博客 504
上一篇: 美团点评 2018春招在线笔试感悟
下一篇: POJ 2018 Best Cow Fences
sortmin
博客等级 码龄9年 45粉丝 178原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值