URAL 1146 Maximum Sum(DP)
| 0 | −2 | −7 | 0 |
| 9 | 2 | −6 | 2 |
| −4 | 1 | −4 | 1 |
| −1 | 8 | 0 | −2 |
Input
Output
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std; const int MAXN = ; int mat[MAXN][MAXN], n;
int sum[MAXN][MAXN]; void calsum() {
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j) sum[i][j] = sum[i - ][j] + mat[i][j];
} int solve() {
int ans = -;
for(int r1 = ; r1 <= n; ++r1) {
for(int r2 = r1; r2 <= n; ++r2) {
int t = ;
for(int j = ; j <= n; ++j) {
t += sum[r2][j] - sum[r1 - ][j];
ans = max(t, ans);
if(t < ) t = ;
}
}
}
return ans;
} int main() {
scanf("%d", &n);
for(int i = ; i <= n; ++i)
for(int j = ; j <= n; ++j) scanf("%d", &mat[i][j]);
calsum();
printf("%d\n", solve());
}
URAL 1146 Maximum Sum(DP)的更多相关文章
- 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).就不知道该怎么办了.问了一下,是压缩矩阵,转 ...
- 【noi 2.6_1481】Maximum sum(DP)
题意:求不重叠的2段连续和的最大值. 状态定义f[i]为必选a[i]的最大连续和,mxu[i],mxv[i]分别为前缀和后缀的最大连续和. 注意:初始化f[]为0,而max值为-INF.要看好数据范围 ...
- 最大子矩阵和 URAL 1146 Maximum Sum
题目传送门 /* 最大子矩阵和:把二维降到一维,即把列压缩:然后看是否满足最大连续子序列: 好像之前做过,没印象了,看来做过的题目要经常看看:) */ #include <cstdio> ...
- ural 1146. Maximum Sum
1146. Maximum Sum Time limit: 0.5 secondMemory limit: 64 MB Given a 2-dimensional array of positive ...
- UVA 10891 Game of Sum(DP)
This is a two player game. Initially there are n integer numbers in an array and players A and B get ...
- URAL 1146 Maximum Sum & HDU 1081 To The Max (DP)
点我看题目 题意 : 给你一个n*n的矩阵,让你找一个子矩阵要求和最大. 思路 : 这个题都看了好多天了,一直不会做,今天娅楠美女给讲了,要转化成一维的,也就是说每一列存的是前几列的和,也就是说 0 ...
- URAL 1586 Threeprime Numbers(DP)
题目链接 题意 : 定义Threeprime为它的任意连续3位上的数字,都构成一个3位的质数. 求对于一个n位数,存在多少个Threeprime数. 思路 : 记录[100, 999]范围内所有素数( ...
- Max Sum (dp)
Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. F ...
随机推荐
- yii多数据库
Yii中同时连接多个数据库 Published by 荒野无灯 on 2011-07-09 02:12:45 under PHP/Yii Tags:yii,database 14162 views 0 ...
- HBase的几种调优(GC策略,flush,compact,split)
一:GC的调优 1.jvm的内存 新生代:存活时间较短,一般存储刚生成的一些对象 老年代:存活时间较长,主要存储在应用程序中生命周期较长的对象 永久代:一般存储meta和class的信息 2.GC策略 ...
- Qt数据库操作(qt-win-commercial-src-4.3.1,VC6,Oracle,SQL Server)
qt-win-commercial-src-4.3.1.qt-x11-commercial-src-4.3.1Microsoft Visual C++ 6.0.KDevelop 3.5.0Window ...
- QList内存释放(看它内部存储的是否是Object,另外还有qDeleteAll)
QList<T> 的释放分两种情况: 1.T的类型为非指针,这时候直接调用clear()方法就可以释放了,看如下测试代码 #include <QtCore/QCoreApplicat ...
- PMP--案例解答要点
没有相关的管理流程或方针: 没有进行良好的策划: 资源不足(人.资金.设备和工具): 缺少培训,不具备相关的知识和技能要求: 项目干系人识别不充分,干系人没有充分的介入: 缺少配置管理.变更控制和版本 ...
- 超爱http://www.runoob.com/菜鸟编程
超爱http://www.runoob.com/菜鸟编程 http://www.runoob.com/
- Java: Difference between ArrayList and LinkedList
Basically, they are just two different implementations of List interface. LinkedList is implemented ...
- POJ1528问题解答
#include <iostream>#include <cstdio>#include <cmath> #include <string>#inclu ...
- 由单例模式学到:Lazy<T>
http://www.cnblogs.com/zhangpengshou/archive/2012/12/10/2811765.html http://www.cnblogs.com/anytao/a ...
- linux安装pip报错
解决方法:升级pip工具 sudo python -m pip install -U pip