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

#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. VBS虚拟键码

    1 VK_LBUTTON 鼠标左键 2 VK_RBUTTON 鼠标右键 3 VK_CANCEL Ctrl+Break(通常不需要处理) 4 VK_MBUTTON 鼠标中键 8 VK_BACK Back ...

  2. json 数组 对象 xml 之间转换(待补充)

    json 数组  xml 对象   之间转换(待补充) 1 把对象的类型或者数组转换成字符串类型(或者更确切的说是json类型的). 此处参考链接http://www.jb51.net/article ...

  3. hdu_5676_ztr loves lucky numbers

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5676 在这%一下安神,用了我没见过的黑科技next_permutation,至少我是今天才知道的 #i ...

  4. R语言笔记1--向量、数组、矩阵、数据框、列表

    注释:R语言是区分大小写的 1.向量 R语言中可以将各种向量赋值为一个变量,这种赋值操作符就是等号“=”,也可以使用“<-”. 1)产生向量 (1)函数c() 例如:x1=c(2,4,6,8,0 ...

  5. Why isn't sizeof for a struct equal to the sum of sizeof of each member?

    check here. Basically the compiler will insert unused memory into a structure so that data members a ...

  6. 读书有感——《从毕业生到程序员使用C#开发商业软件》

    本来想自己写个读书感悟之类的东西,但是苦于自己语文水平太差,算了,我把里面觉得很赞的内容摘抄下来就好了(学习都是从模仿开始的嘛). 书籍:<从毕业生到程序猿使用C#开发商业软件> 作者:袁 ...

  7. QML中的ExclusiveGroup

    Exclusive这个单词在高中应该都学过,是互斥的意思.如果你没有上过或者还没有上到高中,那你非常棒,计算机领域的大师很多都是这么起步的. ExclusiveGroup顾名思义就是互斥分组,效果很明 ...

  8. js获取页面的来源页

    <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat=&quo ...

  9. sudo su– user

    [root@localhost ~] # visudo –f /etc/sudoers 在文件中的root账户下添加需要切换root账户的账户 root ALL=(ALL) ALL user ALL= ...

  10. MySql-时间格式转换之转换为时分秒格式的日期

    select date_format(create_datetime,'%Y-%m-%d %k:%i:%s') from busi_repairitem_category MySQL毫秒值和日期的指定 ...