题意:给一个矩阵,里面有正负数,求子矩阵和的最大值

#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <memory.h>
using namespace std;
int s[][],dp[],n,temp[];
int main()
{
// freopen("in.txt","r",stdin);
cin>>n;
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
cin>>s[i][j];
int maxx = ;
for (int i=;i<=n;i++) //start from line i
{
memset(temp,,sizeof(temp));
for (int j=i;j<=n;j++) //end at line j
{
for (int k=;k<=n;k++)
{
temp[k]+=s[j][k];
if (temp[k]+dp[k-]>)
dp[k]=temp[k]+dp[k-];
else
dp[k]=;
if (maxx<dp[k])
maxx =dp[k];
}
}
}
cout << maxx << endl;
}

【矩阵压缩】 poj 1050的更多相关文章

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

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

  2. C++实现矩阵压缩

    C++实现矩阵压缩 转置运算时一种最简单的矩阵运算.对于一个m*n的矩阵M,他的转置矩阵T是一个n*m的矩阵,且T(i,j) = M(j,i). 一个稀疏矩阵的转置矩阵仍然是稀疏矩阵. 矩阵转置 方案 ...

  3. POJ 1050 To the Max 枚举+dp

    大致题意: 求最大子矩阵和 分析: 一开始想复杂了,推出了一个状态方程:d[i][j]=max(d[i][j-1]+-,d[i-1][j]+-).写着写着发现上式省略的部分记录起来很麻烦. 后来发现n ...

  4. Poj 3318 Matrix Multiplication( 矩阵压缩)

    Matrix Multiplication Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18928   Accepted: ...

  5. poj 1050(矩阵求和问题dp)

    To the Max Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44765   Accepted: 23700 Desc ...

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

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

  7. poj 1050 To the Max(线性dp)

    题目链接:http://poj.org/problem?id=1050 思路分析: 该题目为经典的最大子矩阵和问题,属于线性dp问题:最大子矩阵为最大连续子段和的推广情况,最大连续子段和为一维问题,而 ...

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

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

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

随机推荐

  1. (转载)Git使用教程

    转载自:http://www.418log.org/post-89.html .什么是Git 简单地说,Git是 Linux 之父 Linus Trovalds,为管理 Linux 内核代码而建立的, ...

  2. 自定义NSOperation

    一直在思考,每次异步请求都会创建一个新线程,如果我同时发100个异步请求,这样会导致我的内存爆满,应用程序奔溃,因为iOS对开线程有着约束,不能开很多个线程,这就要求我们必须对异步请求进行控制,我一直 ...

  3. Linux Shell 小脚本经典收藏

    原文:http://www.cnblogs.com/Javame/p/3867686.html 1.在两个文件中找出相同的号码 diff -y xx.txt oo.txt | egrep -v &qu ...

  4. jQuery第二章

    一.jQuery选择器 jQuery的行为规则都必须在获取到元素后才能生效.来看一个简单的例子: <p class = “demo”>jQuery Demo</p> <s ...

  5. java写文件时,输出不完整的原因以及解决方法close()或flush()

    在java的IO体系中,写文件通常会用到下面语句 BufferedWriter bw=new BufferedWriter(new FileWriter("sql语句.txt")) ...

  6. openwrt之snmpd

    OpenWRT uses UCI (/etc/config/snmpd) to generate the /etc/snmp/snmpd.conf , so you cannot simply edi ...

  7. As3.0 类的【枚举】

    As3.0 类的枚举   “枚举”是您创建的一些自定义数据类型,用于封装一小组值.ActionScript 3.0 并不支持具体的枚举工具,这与 C++ 使用 enum 关键字或 Java 使用 En ...

  8. 兼容IE低版本

    1,IE6PNG透明的bug,只需要把png图另存为无杂边的png-8格式 2,在IE6用overflow:hidden清除浮动,要加上zoom:1 3,IE6下盒子的最小高度为20px 如果要小于2 ...

  9. 硬盘安装win8系统方法汇总

    从硬盘安装 (推荐)硬盘安装方法一 使用Nt6 hdd installer进行安装,此方法适合XP,vista, Windows 7等系统. 下载Nt6 hdd installer(Win8硬盘安装工 ...

  10. 制作 macOS Sierra 正式版U盘USB启动安装盘方法教程 (全新安装 Mac 系统)

    使用命令行创建制作 macOS Sierra 正式版 USB 安装盘 1.准备一个 8GB 或更大容量的 U盘,并备份好里面的所有资料. 2.下载好 macOS Sierra 正式版的安装程序(app ...