点我看题目

题意 : 给你一个n*n的矩阵,让你找一个子矩阵要求和最大。

思路 : 这个题都看了好多天了,一直不会做,今天娅楠美女给讲了,要转化成一维的,也就是说每一列存的是前几列的和,也就是说

0 -2 -7 0
9 2 -6 2
-4 1 -4 1
-1 8 0 -2

处理后就是:
0  -2  -9  -9
9   11  5   7
-4 -3  -7  -6
-1  7   7   5

 #include <iostream>
#include <stdio.h>
#include <string.h> using namespace std; int sum[][] ;
int main()
{
int n ,m;
while(~scanf("%d",&n))
{
memset(sum,,sizeof(sum)) ;
for(int i = ; i <= n ; i++)
{
for(int j = ; j <= n ; j++)
{
scanf("%d",&m) ;
sum[i][j] = sum[i-][j]+m ;
}
}
int ans = - ;
for(int i = ; i <= n ; i++ )
for(int j = i ; j <= n ; j++)
{
int cnt = ;
for(int k = ; k <= n ; k ++)
{
cnt += sum[j][k]-sum[i-][k] ;
ans = max(cnt,ans) ;
if(cnt < ) cnt = ;
}
}
printf("%d",ans) ;
}
return ;
}

URAL 1146 Maximum Sum & HDU 1081 To The Max (DP)的更多相关文章

  1. URAL 1146 Maximum Sum(最大子矩阵的和 DP)

    Maximum Sum 大意:给你一个n*n的矩阵,求最大的子矩阵的和是多少. 思路:最開始我想的是预处理矩阵,遍历子矩阵的端点,发现复杂度是O(n^4).就不知道该怎么办了.问了一下,是压缩矩阵,转 ...

  2. 最大子矩阵和 URAL 1146 Maximum Sum

    题目传送门 /* 最大子矩阵和:把二维降到一维,即把列压缩:然后看是否满足最大连续子序列: 好像之前做过,没印象了,看来做过的题目要经常看看:) */ #include <cstdio> ...

  3. ural 1146. Maximum Sum

    1146. Maximum Sum Time limit: 0.5 secondMemory limit: 64 MB Given a 2-dimensional array of positive ...

  4. ural 1146. Maximum Sum(动态规划)

    1146. Maximum Sum Time limit: 1.0 second Memory limit: 64 MB Given a 2-dimensional array of positive ...

  5. URAL 1146 Maximum Sum(DP)

    Given a 2-dimensional array of positive and negative integers, find the sub-rectangle with the large ...

  6. URAL 1146 Maximum Sum 最大子矩阵和

    题目:click here #include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; con ...

  7. Timus 1146. Maximum Sum

    1146. Maximum Sum Time limit: 0.5 secondMemory limit: 64 MB Given a 2-dimensional array of positive ...

  8. hdu 1081 To The Max(dp+化二维为一维)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1081 To The Max Time Limit: 2000/1000 MS (Java/Others ...

  9. HDU 1081 To The Max【dp,思维】

    HDU 1081 题意:给定二维矩阵,求数组的子矩阵的元素和最大是多少. 题解:这个相当于求最大连续子序列和的加强版,把一维变成了二维. 先看看一维怎么办的: int getsum() { ; int ...

随机推荐

  1. HOWTO: Be more productive

    ---by   Aaron Swartz HOWTO: Be more productive “With all the time you spend watching TV,” he tells m ...

  2. 第三十二篇、iOS 10开发

    1.语音识别 苹果官方在文档中新增了API   Speech,那么在以前我们处理语音识别非常的繁琐甚至很多时候可能需要借助于第三方框架处理,那么苹果推出了这个后,我们以后处理起来就非常的方便了,spe ...

  3. LINQ中实现 In 与 Not In

    T-SQL的IN: Select ProductID, ProductName, CategoryID From dbo.Products , ) T-SQL的NOT IN: Select Produ ...

  4. 最新模仿ios版微信应用源码

    这个是刚刚从那个IOS教程网http://ios.662p.com分享来的,也是一个很不错的应用源码,仿微信基本功能.基于XMPP服务器的即时通信以及交友客户端. ----第一期代码的功能如下---- ...

  5. 【Android】Android SDK在线更新镜像服务器

    Android SDK在线更新镜像服务器 中国科学院开源协会镜像站地址: IPV4/IPV6: http://mirrors.opencas.cn 端口:80 IPV4/IPV6: http://mi ...

  6. C#定时器

    在C#里关于定时器类就有3个 1.定义在System.Windows.Forms里 2.定义在System.Threading.Timer类里 3.定义在System.Timers.Timer类里 S ...

  7. iterm2 配色修改

    打开终端 输入 cd ~ vim .bash_profile 插入 export CLICOLOR= export LSCOLORS=gxfxcxdxbxegedabagacad export PS1 ...

  8. c#的协变和逆变

    关于协变和逆变要从面向对象继承说起.继承关系是指子类和父类之间的关系:子类从父类继承,所以子类的实例也就是父类的实例.比如说Animal是父类,Dog是从Animal继承的子类:如果一个对象的类型是D ...

  9. CentOS 6.4 中安装部署 Nutch 1.7

    1.配置SSH 自行查阅相关资料 2.安装JDK,配置Java环境 自行查阅相关资料 3.安装SVN [root@master ~]# yum install -y subversion 通过SVN签 ...

  10. 在Linux环境下给php添加mbstring扩展

    1,今天在开发项目的时候使用了一个php函数(mb_strcut),运行代码时候提示报错"call to undefind function mb_strcut",首先检查下函数名 ...