题目链接

题意:给定N*N的矩阵,求该矩阵中和最大的子矩阵的和。

题解:把二维转化成一维,算下就好了。

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll N=1e3+;
ll ans=-,tmp,data[N][N],a[N];
int ansi1=,ansj1=,ansi2=,ansj2=,tmp1=,tmp2=,n,m;
int main()
{
while(scanf("%d",&n)!=EOF){
m=n; ans=-;
memset(data,,sizeof(data));
for(int i=;i<=n;i++)
for(int j=;j<=m;j++){
scanf("%lld",&data[i][j]);
data[i][j]+=data[i-][j];
}
for(int i=;i<=n;i++)
for(int k=;k<i;k++)
{
memset(a,,sizeof(a));
tmp=;
for(int j=;j<=m;j++){
a[j]=data[i][j]-data[k][j];
tmp+=a[j];
tmp=max(tmp,0LL);
ans=max(ans,tmp);
}
}
printf("%lld\n",ans);
}
return ;
}

POJ 1050 To the Max (最大子矩阵和)的更多相关文章

  1. POJ 1050 To the Max 最大子矩阵和(二维的最大字段和)

    传送门: http://poj.org/problem?id=1050 To the Max Time Limit: 1000MS   Memory Limit: 10000K Total Submi ...

  2. poj 1050 To the Max(最大子矩阵之和)

    http://poj.org/problem?id=1050 我们已经知道求最大子段和的dp算法 参考here  也可参考编程之美有关最大子矩阵和部分. 然后将这个扩大到二维就是这道题.顺便说一下,有 ...

  3. poj 1050 To the Max(最大子矩阵之和,基础DP题)

    To the Max Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 38573Accepted: 20350 Descriptio ...

  4. poj 1050 To the Max 最大子矩阵和 经典dp

    To the Max   Description Given a two-dimensional array of positive and negative integers, a sub-rect ...

  5. [ACM_动态规划] POJ 1050 To the Max ( 动态规划 二维 最大连续和 最大子矩阵)

    Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...

  6. hdu 1081 &amp; poj 1050 To The Max(最大和的子矩阵)

    转载请注明出处:http://blog.csdn.net/u012860063 Description Given a two-dimensional array of positive and ne ...

  7. poj - 1050 - To the Max(dp)

    题意:一个N * N的矩阵,求子矩阵的最大和(N <= 100, -127 <= 矩阵元素 <= 127). 题目链接:http://poj.org/problem?id=1050 ...

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

  9. POJ 1050 To the Max -- 动态规划

    题目地址:http://poj.org/problem?id=1050 Description Given a two-dimensional array of positive and negati ...

随机推荐

  1. 在原有的基础之上,启用NAT模型

    # 给虚拟主机实例添加一个网关 route add default gw 192.168.23.1   # 在宿主机打开网卡间转发功能 echo 1 > /proc/sys/net/ipv4/i ...

  2. SpringCloud——服务网关

    1.背景 上篇博客<SpringCloud--Eureka服务注册和发现>中介绍了注册中心Eureka.服务提供者和服务消费者.这篇博客我们将介绍服务网关. 图(1) 未使用服务网关的做法 ...

  3. spring mvc4 找不到静态文件js/css/html 404

    说明: http://localhost:8080 指向的目录是WEB-INF所在的目录,也就是说请求静态资源时都是从该根目录开始查找.建议将所有静态文件放到和WEB-INF同级的目录下. 以 htt ...

  4. CentOS 7 U盘安装问题解决

    最近期待以久的CentOS 7正式版终于发布了,在家里无聊,所以就打算在我的小Y上安装一下,由于笔记本原来有安装Windows 7 操作系统,考虑使用的需求,所以决定安装双系统: 1.         ...

  5. 各大巨头电商提供的IP库API接口-新浪、搜狐、阿里

    新浪的IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js     (不可用)新浪多地域测试方法:http://i ...

  6. Halcon 笔记1

    Halcon Example位置: C:\Users\Public\Documents\MVTec\HALCON-13.0\examples 安装位置:C:\Program Files\MVTec\H ...

  7. p2 关节

    P2中使用Constraint及其子类表示关节,也就是将两个刚体按照指定的规则约束在一起,形成有规律的.相互限制的运动模拟.P2关节模拟中,两个刚体没有通过任何刚体连接,只是通过算法模拟出关节运动轨迹 ...

  8. nodejs 调试

    什么语言入门的准备功能就是写helloworld, 调试. 用惯了chrome的话,推荐用chrome自带的调试器来调试.很方便. 在地址栏中输入 chrome://inspect 并按回车,会打开如 ...

  9. Redis 请求应答模式和往返延时 Pipelining

    Redis是一个CS结构的TCP服务器,使用”请求-应答”的模式.,客户端发起一个请求是这样的步骤: 客户端发送一个请求给服务器,然后等待服务器的响应,一般客户端使用阻塞模式来等待服务器响应. 服务器 ...

  10. SQL Server中使用自定义指定顺序排序

    比如需要对SQL表中的字段NAME进行如下的排序:张三(Z)李四(L)王五(W)赵六(Z) 如果想按 “ 张三.李四.王五.赵六”的顺序排序,则可以使用以下语句: order by charindex ...