zoj1074 To the Max
题目很简单,求一个连续的最大子矩阵的值.
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的更多相关文章
- 随手练——ZOJ-1074 To the Max(最大矩阵和)
To the Max http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1074 动态规划(O(n^3)) 获得一维数组的最大子 ...
- Kafka副本管理—— 为何去掉replica.lag.max.messages参数
今天查看Kafka 0.10.0的官方文档,发现了这样一句话:Configuration parameter replica.lag.max.messages was removed. Partiti ...
- 排序算法----基数排序(RadixSort(L,max))单链表版本
转载http://blog.csdn.net/Shayabean_/article/details/44885917博客 先说说基数排序的思想: 基数排序是非比较型的排序算法,其原理是将整数按位数切割 ...
- [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 ...
- [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. ...
- BZOJ 4390: [Usaco2015 dec]Max Flow
4390: [Usaco2015 dec]Max Flow Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 177 Solved: 113[Submi ...
- supervisor监管进程max file descriptor配置不生效的问题
配置了 sudo vim /etc/security/limits.conf * soft nofile * hard nofile 单独起进程没问题, 放到supervisor下监管启动,则报错 ...
- Max double slice sum 的解法
1. 上题目: Task description A non-empty zero-indexed array A consisting of N integers is given. A tripl ...
- 3ds max 渲染清晰面片的边缘
3ds max的菜单栏 -> 渲染 -> 材质编辑器->精简材质编辑器,将面状打勾,如下图,就能渲染出面片清晰的图形.
随机推荐
- git push -u origin master 上传出错问题
============================================ 跟着廖学锋教程初学git发现个很奇怪的问题,后面原来发现是这样,有点逗.. ================= ...
- git 用户手册
Git是一个分布式版本控制/软件配置管理软件,原来是linux内核开发者林纳斯·托瓦兹为了更好地管理linux内核开发而创立的.需要注意的是和GNU Interactive Tools,一个类似Nor ...
- javascript 控制input
1.只允许输入数字 <input name="username" type="text" onkeyup="value=this.val ...
- (转)三角函数计算,Cordic 算法入门
由于最近要使用atan2函数,但是时间上消耗比较多,因而网上搜了一下简化的算法. 原帖地址:http://blog.csdn.net/liyuanbhu/article/details/8458769 ...
- mac git 命令提示
直接进入正题: $ brew list 查看你是否已经安装了"bash-completion",如果没有,继续往下看: $ brew install bash-completion ...
- How Many Tables--hdu1213(并查集)
How Many Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- PHP配置xdebug
其实已经做PHP超过2年了,但是今天特别有感触,所以把过程写在这里 环境是win7+apache2.2+php5.3,因为某种原因,必须使用这个版本. 然后就死活配置不出来.apache日志如下: [ ...
- Nginx 配置指令的执行顺序(七)
来看一个 ngx_static 模块服务磁盘文件的例子.我们使用下面这个配置片段: location / { root /var/www/; } 同时在本机的 /var/w ...
- Nginx 变量漫谈(三)
也有一些内建变量是支持改写的,其中一个例子是 $args. 这个变量在读取时返回当前请求的 URL 参数串(即请求 URL 中问号后面的部分,如果有的话 ),而在赋值时可以直接修改参数串.我们来看一个 ...
- android事件详解
http://blog.csdn.net/asce1885/article/details/7596669 http://blog.csdn.net/liranke/article/details/6 ...