poj 1050 To the Max 最大子矩阵和 经典dp
Description
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
Output
Sample Input
4
0 -2 -7 0 9 2 -6 2
-4 1 -4 1 -1 8 0 -2
Sample Output
15
Source
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll __int64
#define mod 1000000007
#define pi (4*atan(1.0))
const int N=1e3+,M=1e6+,inf=1e9+;
int a[N][N];
int sum[N][N];
int num[N];
int main()
{
int x,y,z,i,t;
while(~scanf("%d",&x))
{
memset(sum,,sizeof(sum));
for(i=;i<=x;i++)
for(t=;t<=x;t++)
scanf("%d",&a[i][t]);
for(i=;i<=x;i++)
for(t=;t<=x;t++)
sum[t][i]=sum[t-][i]+a[t][i];
int maxx=-inf;
for(i=;i<=x;i++)
{
for(t=i;t<=x;t++)
{
for(int j=;j<=x;j++)
num[j]=sum[t][j]-sum[i-][j];
int sum=;
for(int j=;j<=x;j++)
{
sum+=num[j];
maxx=max(maxx,sum);
if(sum<)
sum=;
}
}
}
printf("%d\n",maxx);
}
return ;
}
poj 1050 To the Max 最大子矩阵和 经典dp的更多相关文章
- POJ 1050 To the Max 最大子矩阵和(二维的最大字段和)
传送门: http://poj.org/problem?id=1050 To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submi ...
- poj 1050 To the Max(最大子矩阵之和)
http://poj.org/problem?id=1050 我们已经知道求最大子段和的dp算法 参考here 也可参考编程之美有关最大子矩阵和部分. 然后将这个扩大到二维就是这道题.顺便说一下,有 ...
- poj 1050 To the Max(最大子矩阵之和,基础DP题)
To the Max Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 38573Accepted: 20350 Descriptio ...
- POJ 1050 To the Max (最大子矩阵和)
题目链接 题意:给定N*N的矩阵,求该矩阵中和最大的子矩阵的和. 题解:把二维转化成一维,算下就好了. #include <cstdio> #include <cstring> ...
- poj 1050 To the Max(线性dp)
题目链接:http://poj.org/problem?id=1050 思路分析: 该题目为经典的最大子矩阵和问题,属于线性dp问题:最大子矩阵为最大连续子段和的推广情况,最大连续子段和为一维问题,而 ...
- [ACM_动态规划] POJ 1050 To the Max ( 动态规划 二维 最大连续和 最大子矩阵)
Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...
- hdu 1081 & poj 1050 To The Max(最大和的子矩阵)
转载请注明出处:http://blog.csdn.net/u012860063 Description Given a two-dimensional array of positive and ne ...
- poj - 1050 - To the Max(dp)
题意:一个N * N的矩阵,求子矩阵的最大和(N <= 100, -127 <= 矩阵元素 <= 127). 题目链接:http://poj.org/problem?id=1050 ...
- POJ 1050 To the Max 暴力,基础知识 难度:0
http://poj.org/problem?id=1050 设sum[i][j]为从(1,1)到(i,j)的矩形中所有数字之和 首先处理出sum[i][j],此时左上角为(x1,y1),右下角为(x ...
随机推荐
- PHP error_log 新认知
//error_log 简介及使用方法 // error_log("消息","类型","路径"); //message //type ...
- Oracle扩容表空间
1.程序报错,无法进行修改操作,通过日志,看到如下错误 2.通过google查询,问题是表空间文件不够了 "表空间大小(M)",(a.bytes "已使用空间(M)&qu ...
- jsonp解决跨域问题
日常开发网页中,时常遇到跨域问题,通常解决办法:后端提供的接口支持jsonp格式,前端采用dataType:jsonp. 一:Jquery封装的AJAX,dataType:jsonp格式的方法: $. ...
- 转载SQL_trace 和10046使用
SQL_TRACE是Oracle提供的用于进行SQL跟踪的手段,是强有力的辅助诊断工具.在日常的数据库问题诊断和解决中,SQL_TRACE是非常常用的方法.本文就SQL_TRACE的使用作简单探讨,并 ...
- 404 Not Found 探秘Nginx转发处理流程
一.问题描述 访问一个链接地址后报404 Not Found nginx/1.10.2 1 112.95.211.154 - - [08/Mar/2018:15:22:21 +0800] " ...
- Centos 6.5 Install Mysql 8.0.0
依赖包 yum install numactl libaio perl-Time-HiRes per-devel -y 下载对应系统版本下载 wget http://cdn.mysql.com//Do ...
- 页面调用dll
1:本地安装vs2010,有时报错缺少WindowsSP1更新包,下载安装即可. 2:安装完成后,打开VS2010, 3:文件--新建--项目,找到ATL项目(一种COM组件写法),输入项目名称,点击 ...
- 为MarS Board安装无线网卡Linux驱动
玩了几天MarS Board,发现要了解Linux是如何工作的,从嵌入式开发板玩起最有效率.因为会遇到无数的问题和未知领域,然后在解决问题的过程中有深入了解Linux的机会. 为这块开发板专门买了 ...
- JS的checkbox状态切换dom无变化
今天调试checkbox,手动加上checked="checked"和去掉,都对实际页面没有产生影响 搜索一番 1.对radio .checkbox 来说说,checked属性可以 ...
- 20145302张薇《Java程序设计》第十六周课程总结
20145302 <Java程序设计>第十六周课程总结 实验报告链接汇总 实验一 Java开发环境的熟悉 实验二 Java面向对象程序设计 实验三 敏捷开发与XP实践 实验四 Andoid ...