最大子矩阵和 URAL 1146 Maximum Sum
/*
最大子矩阵和:把二维降到一维,即把列压缩;然后看是否满足最大连续子序列;
好像之前做过,没印象了,看来做过的题目要经常看看:)
*/
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std; const int MAXN = 1e2 + ;
const int INF = 0x3f3f3f3f;
int a[MAXN][MAXN];
int dp[MAXN][MAXN][MAXN]; int main(void) //URAL 1146 Maximum Sum
{
//freopen ("D.in", "r", stdin); int n;
while (scanf ("%d", &n) == )
{
int ans = -INF;
memset (dp, , sizeof (dp));
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=; j<=n; ++j)
{
int sum = ;
for (int k=j; k>=; --k)
{
sum += a[i][k];
dp[i][j][k] = max (sum + dp[i-][j][k], sum);
ans = max (ans, dp[i][j][k]);
}
}
} printf ("%d\n", ans);
} return ;
}
最大子矩阵和 URAL 1146 Maximum Sum的更多相关文章
- ural 1146. Maximum Sum
1146. Maximum Sum Time limit: 0.5 secondMemory limit: 64 MB Given a 2-dimensional array of positive ...
- 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 最大子矩阵和
题目:click here #include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; con ...
- URAL 1146 Maximum Sum & HDU 1081 To The Max (DP)
点我看题目 题意 : 给你一个n*n的矩阵,让你找一个子矩阵要求和最大. 思路 : 这个题都看了好多天了,一直不会做,今天娅楠美女给讲了,要转化成一维的,也就是说每一列存的是前几列的和,也就是说 0 ...
- Timus 1146. Maximum Sum
1146. Maximum Sum Time limit: 0.5 secondMemory limit: 64 MB Given a 2-dimensional array of positive ...
- UVa 108 - Maximum Sum(最大连续子序列)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- UVa 10827 - Maximum sum on a torus
题目大意:UVa 108 - Maximum Sum的加强版,求最大子矩阵和,不过矩阵是可以循环的,矩阵到结尾时可以循环到开头.开始听纠结的,想着难道要分情况讨论吗?!就去网上搜,看到可以通过补全进行 ...
随机推荐
- 用了那么久居然没发现firefox快捷键有如此多
firefox用了也有好几年了,除了ytkah经常用到的搜索Ctrl+F.加入书签Ctrl+D.打开新便签Ctrl+T,鼠标右键菜单,还安装了鼠标手势插件FireGestures,快速关闭标签.撤销关 ...
- U盘安装Linux安装报错及解决方案
导读 从网上看到了<Linux就该这么学>后,偏离软件行业多年的我下定决心回归!这篇文章是我这一个小白的亲身经历,希望能被采纳! 开始按照<Linux就该这么学>中所讲在自己的 ...
- Proc 和 代码块
文章是从个人博客 搬过来的,大家也可以直接访问我的个人博客哦http://www.iwangzheng.com/ 如何将一段代码从对象中取出并将它像对象一样传递.在ruby中,一个Proc是一个包含一 ...
- C++中new的解说
new int;//开辟一个存放整数的存储空间,返回一个指向该存储空间的地址(即指针) new int(100);//开辟一个存放整数的空间,并指定该整数的初值为100,返回一个指向该存储空间的地址 ...
- Redis使用介绍
Redis 是一个高性能的key-value数据库. redis的出现,很大程度补偿了memcached这类keyvalue存储的不足,在部 分场合可以对关系数据库起到很好的补充作用.它提供了Pyth ...
- Continuous Subarray Sum
Given an integer array, find a continuous subarray where the sum of numbers is the biggest. Your cod ...
- Android PopupWindow 消失后的回掉方法
popupwindow 会在点击屏幕其他地方消失,但是这个消失时的回掉方法一直没有找到,困扰了一个多月,差了不少百度,没有很好解决,今天偶然看到了setOnDismissListener这个方法!没想 ...
- apache AllowEncodedSlashes 允许URL中对路径分隔符进行编码
2013年11月29日 10:35:32 情景: 你想通过在当前的URL中记录来源页面的URL,以便处理完请求后再跳转回来源页: http://www.example1.com/refer/http: ...
- 六间房PK同时观看两方视频(绕过VIP限制)+直播状态批量监测
可交换两个视频位置,记住最后播放记录,游客VIP限制也能观看视频等功能. 使用方法: 1.先运行 6.cn.live.exe 分别打开两个主播房间的网页(VIP限制也能获取视频的文件名) (房间已满提 ...
- 5.python(迭代器,装饰器,生成器,基本算法,正则)
一,迭代器 1.迭代器 (1)迭代器是访问集合元素的一种方式.迭代器对象从集合的第一个元素开始访问,知道所有的元素被访问完结束.迭代器只能往前不会后退. (2)对于原生支持随机访问的数据结构(如t ...