题目很简单,求一个连续的最大子矩阵的值.

zoj上的数据非常弱。

首先爆搜是O(N^4),10^8的复杂度略高,那么我们可以处理一下其中一维的前缀和,降一阶,然后按照连续最大子序列来处理,因为可能为负数,所以基数不能取0.

上代码

#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<iostream>
#include<cstring>
using namespace std;
int n;
int a[105][105];
int dp[105];
int main()
{
int t;
//freopen("input.txt","r",stdin);
scanf("%d",&n);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
scanf("%d",&t);
a[i][j]=a[i][j-1]+t;
}//每一行的前缀和
int res=-1280000;
for(int i=0;i<=n;i++)
for(int j=i+1;j<=n;j++)
{
memset(dp,0,sizeof(dp));
for(int k=1;k<=n;k++)
{
int t=a[k][j]-a[k][i];
if(dp[k-1]<0)
dp[k]=t;
else
dp[k]=dp[k-1]+t;
if(dp[k]>res)
res=dp[k];
}
}
printf("%d\n",res);
}

zoj1074 To the Max的更多相关文章

  1. 随手练——ZOJ-1074 To the Max(最大矩阵和)

    To the Max http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1074 动态规划(O(n^3)) 获得一维数组的最大子 ...

  2. Kafka副本管理—— 为何去掉replica.lag.max.messages参数

    今天查看Kafka 0.10.0的官方文档,发现了这样一句话:Configuration parameter replica.lag.max.messages was removed. Partiti ...

  3. 排序算法----基数排序(RadixSort(L,max))单链表版本

    转载http://blog.csdn.net/Shayabean_/article/details/44885917博客 先说说基数排序的思想: 基数排序是非比较型的排序算法,其原理是将整数按位数切割 ...

  4. [LeetCode] Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K

    Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...

  5. [LeetCode] Max Points on a Line 共线点个数

    Given n points on a 2D plane, find the maximum number of points that lie on the same straight line. ...

  6. BZOJ 4390: [Usaco2015 dec]Max Flow

    4390: [Usaco2015 dec]Max Flow Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 177  Solved: 113[Submi ...

  7. supervisor监管进程max file descriptor配置不生效的问题

    配置了 sudo vim /etc/security/limits.conf * soft nofile * hard nofile   单独起进程没问题, 放到supervisor下监管启动,则报错 ...

  8. Max double slice sum 的解法

    1. 上题目: Task description A non-empty zero-indexed array A consisting of N integers is given. A tripl ...

  9. 3ds max 渲染清晰面片的边缘

    3ds max的菜单栏 -> 渲染 -> 材质编辑器->精简材质编辑器,将面状打勾,如下图,就能渲染出面片清晰的图形.

随机推荐

  1. 如何写一个数据库How do you build a database?(转载)

    转载自:http://www.reddit.com/r/Database/comments/27u6dy/how_do_you_build_a_database/ciggal8 Its a great ...

  2. go import

    import "fmt"最常用的一种形式 import "./test"导入同一目录下test包中的内容 import f "fmt"导入f ...

  3. inflate, findViewById与setContentView的区别与联系

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentV ...

  4. SquirrelMQ消息队列

    SquirrelMQ是一个快速的消息队列. SquirrelMQ特性: 1. SquirrelMQ使用Slab内存分配算法来降低内存碎片,使用epoll来解决高并发问题.效率比redis要高,使用简单 ...

  5. php递归函数,性能给力

    function arPro($data,$res=array(),$pid='0',$level='0'){ foreach ($data as $k => $v){ if($v['comme ...

  6. Window10安装TestLink,以及登录mysql数据库的错误处理

    步骤一: 需要安装apache和mysql,但是我们这里仅仅是使用testlink,不关注其他,所以使用Vertrigoserv进行傻瓜式安装,安装完后,下载testlink解压,将解压后的文件放入D ...

  7. {A} + {B}(unique水)

    {A} + {B} Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  8. QT使用WOL实现远程一键开机(局域网)

    功能:让关机的电脑一键开机,需要目标电脑的主板支持,并且插上网线: 效果:相当于手动按了一下目标电脑的开关机按钮. 没啥技术含量,简单开说... 1.获取目标机MAC地址 QByteArray sMa ...

  9. 使用AES加密的帮助类

    在开发中经常使用加密/解密对一些内容进行处理,比如密码在存入数据库之前先经过加密处理等等,这里就把一个加密帮助类代码贴出来,供以后查找使用. 这个帮助类主要功能是对字符串和字节数组进行加密解密处理. ...

  10. mysql解压版配置

    2. 解压MySQL压缩包 将以下载的MySQL压缩包解压到自定义目录下,我的解压目录是: "D:\Program Files\MySQL\mysql-5.6.13-win32" ...