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的菜单栏 -> 渲染 -> 材质编辑器->精简材质编辑器,将面状打勾,如下图,就能渲染出面片清晰的图形.
随机推荐
- Emmet 语法探析
Emmet 语法探析 Emmet(Zen Coding)是一个能大幅度提高前端开发效率的一个工具. 大多数编辑器都支持Snippet,即存储和重用一些代码块.但是前提是:你必须先定义 这些代码块. E ...
- IE8下的项目在IE11下某些功能无法实现的问题
在IE8和IE11 下获取数据的时间进行判断有些不同,也要根据浏览器的版本判断分别实现 $(".btndelete").children().children().click(fu ...
- Velocity中避免null引起的数据问题
请先看下面一段代码: #foreach($id in [1..50]) #set($user = $User.Get($id)) $id : ${user.name} #end 上面这段代码中,假设只 ...
- 基于java的InputStream.read(byte[] b,int off,int len)算法学习
public int read(byte[] b, int off, int len) throws IOException 将输入流中最多 len 个数据字节读入字节数组.尝试读取多达 len 字节 ...
- Fragment 之 PagerAdapter
package com.edaixi.main.adapter; import android.content.Context; import android.support.v4.view.Page ...
- ios html5 长按复制文本
以前做的项目,主要是针对ios的,安卓上面也没有测试. 原理其实是系统自带的功能,那时候借鉴的其他网站,没有试验通过document.execCommand("Copy"),别的j ...
- 看懂这个sql 你的sql语句就掌握了
某财务报表 USE [PB_AHTC]GO/****** Object: StoredProcedure [dbo].[JSPRO] Script Date: 12/10/2013 11:54:52 ...
- Git学习01 --git add, git commit , git log ,git status, git reset --hard, head
Git官方提供的快速入门教程:https://try.github.io/levels/1/challenges/1 特点:Git极其强大的分支管理:分布式版本 集中式版本控制系统,版本库是集中存放在 ...
- MySQL 5.6 中 TIMESTAMP 的变化
http://www.williamsang.com/archives/818.html
- Sysstat性能监控工具包中20个实用命令
Sysstat性能监控工具包中20个实用命令 学习mpstat, pidstat, iostat和sar等工具,这些工具可以帮组我们找出系统中的问题.这些工具都包含了不同的选项,这意味着你可以根据不同 ...