POJ 1050 To the Max 最大子矩阵和(二维的最大字段和)
传送门:
http://poj.org/problem?id=1050
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 52306 | Accepted: 27646 |
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<stdio.h>
#include<algorithm>
#include<cstring>
#include<math.h>
#include<memory>
#include<queue>
#include<vector>
using namespace std;
#define max_v 105
#define INF 99999999
int dp1[max_v][max_v];//起始i列 终止j列的max
int dp2[max_v];//最大子段和的dp,代表以第i个数结尾的最大子合和值
int a[max_v][max_v];
int f(int j1,int j2,int i)//j1列到j2列,i行上数字的和
{
int sum=;
for(int j=j1;j<=j2;j++)
{
sum+=a[i][j];
}
return sum;
}
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
scanf("%d",&a[i][j]);
memset(dp1,,sizeof(dp1));
dp1[][]=a[][];
int result=-INF;
for(int i=;i<=n;i++)
{
for(int j=i;j<=n;j++)
{
memset(dp2,,sizeof(dp2));
dp2[]=f(i,j,);
int maxv=dp2[];
for(int k=;k<=n;k++)
{
int x=;
if(dp2[k-]>)
x=dp2[k-];
dp2[k]=x+f(i,j,k);
maxv=max(maxv,dp2[k]);
}
dp1[i][j]=maxv;
result=max(result,dp1[i][j]);
}
}
printf("%d\n",result);
}
return ;
}
POJ 1050 To the Max 最大子矩阵和(二维的最大字段和)的更多相关文章
- poj 1050 To the Max(最大子矩阵之和)
http://poj.org/problem?id=1050 我们已经知道求最大子段和的dp算法 参考here 也可参考编程之美有关最大子矩阵和部分. 然后将这个扩大到二维就是这道题.顺便说一下,有 ...
- POJ 1050 To the Max (最大子矩阵和)
题目链接 题意:给定N*N的矩阵,求该矩阵中和最大的子矩阵的和. 题解:把二维转化成一维,算下就好了. #include <cstdio> #include <cstring> ...
- poj 1050 To the Max(最大子矩阵之和,基础DP题)
To the Max Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 38573Accepted: 20350 Descriptio ...
- poj 1050 To the Max 最大子矩阵和 经典dp
To the Max Description Given a two-dimensional array of positive and negative integers, a sub-rect ...
- 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 ...
- poj - 1050 - To the Max(dp)
题意:一个N * N的矩阵,求子矩阵的最大和(N <= 100, -127 <= 矩阵元素 <= 127). 题目链接:http://poj.org/problem?id=1050 ...
- POJ 1050 To the Max 二维最大子段和
To the MaxTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 52281 Accepted: 27633Description ...
- [poj]1050 To the Max dp
Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...
随机推荐
- HDU 2578(二分查找)
686MS #include <iostream> #include <cstdlib> #include <cstdio> #include <algori ...
- IDEA使用maven建web项目示例
运行环境:OSX-10.13.3. IDEA-2017.3.3. maven-3.5.2 步骤1:选择maven-webapp模板新建web项目 步骤2:设置项目GroupId等 需从网上下载相关构件 ...
- OpenStack IceHouse 部署 - 2 - 网络与软件环境初始化
OpenStack应用:节点软硬件环境配置 节点硬件与IP分配 实验室网关 10.14.39.1 各个节点 节点名称 硬件(Linux硬盘分区,RAM,CPU) ip地址(接口) 作用与运行的服 ...
- C#语言总结1
C#C#定义: C#是一门面向对象.面向组件的一门语言,是.NET的一部分. 程序结构: 命名空间 类{ 属性 方法 main函数入口 } 数据类型: C#的数据类型分为:值类型(Value type ...
- WC前的颓废——带花树
QAQ现在很不想写题解博客那就来写个算法吧QAQ... 带花树 题目 来看个题... UOJ79. 某机房里有\(n\)个OIer,其中有\(n\)个男生,\(0\)个女生.现在他们要两两配对. 有\ ...
- Ajax实现表格实时编辑
如果我们的对于一个表格中所有的数据都能在本页进行操作那该是多酷炫的一件事(用起来炒鸡爽)! 用Ajax就可以实现这个功能啦.废话不多说,下面贴出我写的demo吧哈哈.我用的TP框架(3.2)比较习惯啦 ...
- SpringBoot整合mybatis——配置mybatis驼峰命名规则自动转换
一.简述 mybatis驼峰式命名规则自动转换: 使用前提:数据库表设计按照规范“字段名中各单词使用下划线"_"划分”: 使用好处:省去mapper.xml文件中繁琐编写表字段列表 ...
- No value specified for 'Date'错误
今天使用 BeanUtils.copyProperties(m,n); 遇到 No value specified for 'Date' 这个错误,以前用的时候都不需要加 try 今天使用发现需 ...
- CI框架去除index.php
打开apache的配置文件,conf/httpd.conf : LoadModule rewrite_module modules/mod_rewrite.so 把该行前的#去掉. 搜索 AllowO ...
- CentOS随笔 - 3.CentOS7安装Oracle 11g xe
前言 转帖请注明出处: http://www.cnblogs.com/Troy-Lv5/ 由于手上很多项目都是采用Oracle在进行开发, 所以安装Oracle成为必然. 当然有朋友会想为什么不安装1 ...