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 ...
随机推荐
- Linux(Ubuntu)之设定开机自启动
分两种:对自建脚本,对已安装服务 对已安装服务, 只需在/etc/rc.local中添加相应的启动命令,如: 重启后,即可自启动服务. 对自建脚本自启动: 创建脚本test,修改其权限为755,如: ...
- printf 与c的基本类型之间的关系
型 書式 注意事項 ssize_t %zd size_t %zu intmax_t %jd uintmax_t %ju ptrdiff_t %t signed char %hhd unsigned c ...
- 项目配置laungchImage
- android DisplayMetrics 获取屏幕分辨率
Android 提供DisplayMetircs 类可以很方便的获取分辨率.下面介绍 DisplayMetics 类: Andorid.util 包下的DisplayMetrics 类提供了一种关于显 ...
- ListView介绍
原文:http://blog.csdn.net/qingye_love/article/details/13772391?utm_source=tuicool&utm_medium=refer ...
- ACM训练计划建议(写给本校acmer,欢迎围观和指正)
ACM训练计划建议 From:freecode# Date:2015/5/20 前言: 老师要我们整理一份训练计划给下一届的学弟学妹们,整理出来了,费了不少笔墨,就也将它放到博客园上供大家参考. 菜 ...
- freemarker 实现对URL的安全编码
[#setting url_escaping_charset='utf-8'] ${yourstr?url}
- Oracle 10g Block Change Tracking特性
Using Block Change Tracking to Improve Incremental Backup Performance 使用块改变跟踪改善增量备份的性能 The block cha ...
- ORA-1461 encountered when generating server alert SMG-3500
Doc ID 461911.1 Patch 6602742 Applies to: Oracle Database - Enterprise Edition - Version 10.2.0.3 an ...
- Windows Live Writer技巧
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:今天的内容虽然和开发技术无关,却应该和喜欢写东西的技术人员有关,比如我所有的文章都是用 ...