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的菜单栏 -> 渲染 -> 材质编辑器->精简材质编辑器,将面状打勾,如下图,就能渲染出面片清晰的图形.
随机推荐
- C# 枚举运用"位"操作和"或"操作
定义: /// <summary> /// The js function type(the same as name). /// </summary> [Flags] pub ...
- Maximum Subarray (JAVA)
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- Python-windows服务-重启自动化
一. 前言 有了上一篇的“python初学”的基础,咱们就有了python的开发包,有了开发环境IDE,那我们就可以干活了.我的第一个选题就是让我们的windows服务可以按照我们的意愿进行自动重启. ...
- 简单的javascript实例二(随页面滚动广告效果)
方便以后copy 页面代码: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "htt ...
- java 成神之路
一.基础篇 1.1 JVM 1.1.1. Java内存模型,Java内存管理,Java堆和栈,垃圾回收 http://www.jcp.org/en/jsr/detail?id=133 http://i ...
- FreeImage裁剪示例
//截图 int cropImage(const char* file, int left, int top, int right, int bottom, BYTE* &dstData, D ...
- PowerDesigner中NAME和COMMENT的互相转换,需要执行语句
原文: http://www.cnblogs.com/xnxylf/p/3288718.html 由于PDM 的表中 Name 会默认=Code 所以很不方便, 所以需要将 StereoType 显示 ...
- Goldbach's Conjecture(哥德巴赫猜想)
Goldbach's Conjecture Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- Linux命令(持续更新ing)
*.命令语法: a.在进行参数设定时,通常为“-”号,若为完整参数名称,则输入“--”符号; b.指令太长的时候,可以使用“\”符号使指令连续到下一行; c.各种符号的意义: '' ...
- 【DSA MOOC】有序向量二分查找的三个 版本
内容来自 TsinghuaX: 30240184X 数据结构(2015秋) 课程的Vector一章,对有序向量的二分查找有三个版本 三个版本的函数原型是一致的,都是 Rank search(T con ...