poj1050
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 39081 | Accepted: 20639 |
Description
As an example, the maximal sub-rectangle of the array:
0 -2 -7 0
9 2 -6 2
-4 1 -4 1
-1 8 0 -2
is in the lower left corner:
9 2
-4 1
-1 8
and has a sum of 15.
Input
input consists of an N * N array of integers. The input begins with a
single positive integer N on a line by itself, indicating the size of
the square two-dimensional array. This is followed by N^2 integers
separated by whitespace (spaces and newlines). These are the N^2
integers of the array, presented in row-major order. That is, all
numbers in the first row, left to right, then all numbers in the second
row, left to right, etc. N may be as large as 100. The numbers in the
array will be in the range [-127,127].
Output
Sample Input
4
0 -2 -7 0 9 2 -6 2
-4 1 -4 1 -1 8 0 -2
Sample Output
15
/*
* File: main.cpp
* Author: liaoyu <liaoyu@whu.edu.cn>
*
* Created on April 1, 2014, 5:34 PM
*/ #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <algorithm>
using namespace std; int a[][]; int maxSubArray(int n, int* a)
{
int max = 0x80000000;
int b = a[];
for (int i = ; i < n; i++) {
if (b > )b += a[i];
else b = a[i];
if (b > max)max = b;
}
return max;
}
int b[]; int main()
{
int n;
scanf("%d", &n);
int max = 0x80000000;
for (int i = ; i < n; i++)
for (int j = ; j < n; j++)
scanf("%d", &a[i][j]);
for (int i = ; i < n; i++)
for (int j = i; j < n; j++) {
for (int l = ; l < n; l++) {
b[l] = ;
for (int k = i; k <= j; k++) {
b[l] += a[l][k];
}
}
int tmp = maxSubArray(n, b);
if (tmp > max)max = tmp;
}
printf("%d\n", max);
}
poj1050的更多相关文章
- 【poj1050】 To the Max
http://poj.org/problem?id=1050 (题目链接) 题意 求二维最大子矩阵 Solution 数据好像很水,N最大才100,N^4大暴力都可以随便水过. 其实有N^3的做法.枚 ...
- [POJ1050]To the Max
[POJ1050]To the Max 试题描述 Given a two-dimensional array of positive and negative integers, a sub-rect ...
- POJ1050:To the max
poj1050:http://poj.org/problem?id=1050 * maximum-subarray 问题的升级版本~ 本题同样是采用DP思想来做,同时有个小技巧处理:就是把二维数组看做 ...
- [POJ1050] To the Max 及最大子段和与最大矩阵和的求解方法
最大子段和 Ο(n) 的时间求出价值最大的子段 #include<cstdio> #include<iostream> using namespace std; int n,m ...
- [POJ1050]To the Max (矩阵,最大连续子序列和)
数据弱,暴力过 题意 N^N的矩阵,求最大子矩阵和 思路 悬线?不需要.暴力+前缀和过 代码 //poj1050 //n^4暴力 #include<algorithm> #include& ...
- DP----入门的一些题目(POJ1088 POJ1163 POJ1050)
动态规划入门 DP 基本思想 具体实现 经典题目 POJ1088 POJ1163 POJ1050 (一) POJ1088,动态规划的入门级题目.嘿嘿,连题目描述都是难得一见的中文. 题目分析: 求最长 ...
- POJ1050 To the Max 最大子矩阵
POJ1050 给定一个矩阵,求和最大的子矩阵. 将每一列的值进行累加,枚举起始行和结束行,然后就可以线性优化了 复杂度O(n^3) #include<cstdio> #include&l ...
- [POJ1050]To the Max(最大子矩阵,DP)
题目链接:http://poj.org/problem?id=1050 发现这个题没有写过题解,现在补上吧,思路挺经典的. 思路就是枚举所有的连续的连续的行,比如1 2 3 4 12 23 34 45 ...
- poj1050(nyoj104 zoj1074)dp问题
To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 39913 Accepted: 21099 Desc ...
随机推荐
- Android学习笔记——权限解释
<!--允许读取电话状态SIM的权限--><uses-permission android:name="android.permission.READ_PHONE_STAT ...
- Fastboot模式和Recovery模式
http://blog.csdn.net/luoshengyang/article/details/29688041 在回答第一个问题之前,我们先来看看Android设备从硬件到系统的结构,如图1所示 ...
- 强势回归,Linux blk用实力证明自己并不弱!
Flash的出现把存储的世界搅翻了天,仿佛一夜之间发现了新大陆,所有旧世界的东西都变得笨拙.NVMe驱动义无反顾地抛弃了Linux blk,开发自己的队列管理. 当第一次看到NVMe重新使用Linux ...
- Hibernate之二级缓存
Hibernate之二级缓存 一.简介 Gaving King曾经对别人说,hibern ...
- android-8~23 View.java - dispatchTouchEvent源码
android-8 /** * Pass the touch screen motion event down to the target view, or this * view if it is ...
- 【转】EXCEL不显示科学计数法
源地址:http://jingyan.baidu.com/article/e4d08ffdcc304e0fd3f60d69.html 2法无效,不知道为何
- mysql-5.7.16 解压版安装
下载压缩包后,解压到任盘 配置环境变量: 将“C:\MySQL;”加入到环境变量Path中 重命名my-default.ini为my.ini 修改my.ini内容: basedir =C:\MySQL ...
- dos笔记
MS DOS 命令大全 一.基础命令 1 dir 无参数:查看当前所在目录的文件和文件夹. /s:查看当前目录已经其所有子目录的文件和文件夹. /a:查看包括隐含文件的所有文件. /ah:只显示出隐含 ...
- 阐述ArrayList、Vector、LinkedList的存储性能和特性?(转)
ArrayList 和Vector他们底层的实现都是一样的,都是使用数组方式存储数据,此数组元素数大于实际存储的数据以便增加和插入元素,它们都允许直接按序号索引元素,但是插入元素要涉及数组元素移动等内 ...
- 02-C#入门(枚举、结构等)
不要为了写笔记而学习!!! 其实学完一章再返回复习,然后做笔记,真的很费时间(电子书还不方便).当然,复习带来的价值,是值得花时间的. 枚举.结构 枚举的类型有限(short.byte...)且是相同 ...