ural 1146. Maximum Sum
1146. Maximum Sum
Memory limit: 64 MB
| 0 | −2 | −7 | 0 |
| 9 | 2 | −6 | 2 |
| −4 | 1 | −4 | 1 |
| −1 | 8 | 0 | −2 |
Input
Output
Sample
| input | output |
|---|---|
4 |
15 |
/**
Create By yzx - stupidboy
*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef double DB;
#define MIT (2147483647)
#define INF (1000000001)
#define MLL (1000000000000000001LL)
#define sz(x) ((int) (x).size())
#define clr(x, y) memset(x, y, sizeof(x))
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define ft first
#define sd second
#define mk make_pair inline int Getint()
{
int Ret = ;
char Ch = ' ';
bool Flag = ;
while(!(Ch >= '' && Ch <= ''))
{
if(Ch == '-') Flag ^= ;
Ch = getchar();
}
while(Ch >= '' && Ch <= '')
{
Ret = Ret * + Ch - '';
Ch = getchar();
}
return Flag ? -Ret : Ret;
} const int N = ;
int n, arr[N][N];
int sum[N][N], p[N]; inline void Input()
{
scanf("%d", &n);
for(int i = ; i <= n; i++)
for(int j = ; j <= n; j++) scanf("%d", &arr[i][j]);
} inline int Work(int *arr)
{
int ret = arr[], cnt = arr[];
for(int i = ; i <= n; i++)
{
if(cnt < ) cnt = arr[i];
else cnt += arr[i];
ret = max(ret, cnt);
}
return ret;
} inline void Solve()
{
int ans = -INF;
for(int i = ; i <= n; i++)
for(int j = ; j <= n; j++)
sum[i][j] = sum[i - ][j] + arr[i][j];
for(int i = ; i <= n; i++)
for(int j = i; j <= n; j++)
{
for(int k = ; k <= n; k++)
p[k] = sum[j][k] - sum[i - ][k];
int cnt = Work(p);
/*if(ans < cnt)
{
ans = cnt;
printf("%d %d %d\n", ans, i, j);
}*/
ans = max(ans, cnt);
} cout << ans << endl;
} int main()
{
freopen("a.in", "r", stdin);
Input();
Solve();
return ;
}
ural 1146. Maximum Sum的更多相关文章
- 最大子矩阵和 URAL 1146 Maximum Sum
题目传送门 /* 最大子矩阵和:把二维降到一维,即把列压缩:然后看是否满足最大连续子序列: 好像之前做过,没印象了,看来做过的题目要经常看看:) */ #include <cstdio> ...
- ural 1146. Maximum Sum(动态规划)
1146. Maximum Sum Time limit: 1.0 second Memory limit: 64 MB Given a 2-dimensional array of positive ...
- URAL 1146 Maximum Sum(最大子矩阵的和 DP)
Maximum Sum 大意:给你一个n*n的矩阵,求最大的子矩阵的和是多少. 思路:最開始我想的是预处理矩阵,遍历子矩阵的端点,发现复杂度是O(n^4).就不知道该怎么办了.问了一下,是压缩矩阵,转 ...
- URAL 1146 Maximum Sum(DP)
Given a 2-dimensional array of positive and negative integers, find the sub-rectangle with the large ...
- URAL 1146 Maximum Sum & HDU 1081 To The Max (DP)
点我看题目 题意 : 给你一个n*n的矩阵,让你找一个子矩阵要求和最大. 思路 : 这个题都看了好多天了,一直不会做,今天娅楠美女给讲了,要转化成一维的,也就是说每一列存的是前几列的和,也就是说 0 ...
- URAL 1146 Maximum Sum 最大子矩阵和
题目:click here #include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; con ...
- Timus 1146. Maximum Sum
1146. Maximum Sum Time limit: 0.5 secondMemory limit: 64 MB Given a 2-dimensional array of positive ...
- POJ2479 Maximum sum[DP|最大子段和]
Maximum sum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39599 Accepted: 12370 Des ...
- UVa 108 - Maximum Sum(最大连续子序列)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
随机推荐
- 浏览器方法及代码打包成APP的
<script src=" http://static.ydbimg.com/API/YdbOnline.js" type="text/javascript&quo ...
- hadoop 2.5 hdfs namenode –format 出错Usage: java NameNode [-backup] |
在 cd /home/hadoop/hadoop-2.5.2/bin 下 执行的./hdfs namenode -format 报错[hadoop@node1 bin]$ ./hdfs nameno ...
- 昨晚值班将发dla的程序改好后放入正式环境
可是在修改的topic的发送文件中出现有节点没有对应,整个过程陆续调至有20分钟最后11电把新程序换掉.
- linux清除当前屏幕
linux清除当前屏幕:直接clear命令即可 而在windows下的话用cls命令
- 在python中使用concurrent.futures实现进程池和线程池
#!/usr/bin/env python # -*- coding: utf-8 -*- import concurrent.futures import time number_list = [1 ...
- Hihicoder 题目1 : Trie树(字典树,经典题)
题目1 : Trie树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编 ...
- AngularJS讲义 - 作用域
什么是作用域? Angular中作用域(scope)是模板以及工作的上下文环境,作用域中存放了应用模型和视图相关的回调行为.作用域是层次化结构的与相关联的DOM结构相对应.作用域可以观察表达式以及传播 ...
- Atlas 安装和配置
前提得配置好主从:http://www.cnblogs.com/super-d2/p/4802990.html 首先,先去下载Altas的rpm包,下载地址:https://github.com/Qi ...
- android 入门-本地化语言
打包安装到手机上,改变手机系统语言,你在看看是不是改变了.哇.真的可以.
- 【leetcode】plus One
问题描述: Given a non-negative number represented as an array of digits, plus one to the number. The dig ...