URAL 1146 Maximum Sum 最大子矩阵和
题目:click here
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const int INF = 0x3f3f3f3f;
const int M = 2e2+; int n;
int a[M][M]; // a[i][j] 表示从[i][0]到[i][j]的和
int main() {
while( ~scanf("%d", &n ) ) {
memset( a, , sizeof(a) );
for( int i=; i<=n; i++ ) {
for( int j=; j<=n; j++ ) {
scanf("%d", &a[i][j] );
a[i][j] += a[i][j-];
}
}
int ret = -INF;
for( int i=; i<=n; i++ ) {
for( int j=; j<i; j++ ) {
int sum = ;
for( int h=; h<=n; h++ ) {
sum += a[h][i] - a[h][j];
ret = max( ret, sum );
if( sum < ) sum = ;
}
}
}
printf("%d\n", ret );
}
return ;
}
URAL 1146 Maximum Sum 最大子矩阵和的更多相关文章
- 最大子矩阵和 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 ...
- 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 ...
- 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的加强版,求最大子矩阵和,不过矩阵是可以循环的,矩阵到结尾时可以循环到开头.开始听纠结的,想着难道要分情况讨论吗?!就去网上搜,看到可以通过补全进行 ...
随机推荐
- Clear all username or password for login.
Open cmd.exe In command, type in: control keymgr.dll. This is go to watch the password which you rem ...
- 富文本编辑器ckeditor继承
新建一个web项目ckfinder,导入lib包 加入java包,编码格式UTF-8 在WebRoot下添加ckedtior以及ckfinder两个文件夹,将config.xml拷入WEB-INF中 ...
- QT小记之在VS2005中使用(设置QMAKESPEC环境变量,以及编译QT Lib)
QT的结构很清晰明了,看过第一个HELLO WORLD便爱上了它,感觉CEGUI有借鉴过QT的设计.如何在Windows平台下使用QT开发?一,下载SDK包请去官网(QT被NOKIA收购,貌似使用协议 ...
- Codeforces 700B Connecting Universities(树形DP)
[题目链接] http://codeforces.com/problemset/problem/700/B [题目大意] 给出 一棵n个节点的树, 现在在这棵树上选取2*k个点,两两配对,使得其配对的 ...
- HDU 1012 u Calculate e
题解:直接模拟 #include <cstdio> int main(){ puts("n e");puts("- -----------");pu ...
- HDU Tickets(简单的dp递推)
Tickets Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- #ifndef 与 #program once 的区别(转)
转自http://hi.baidu.com/hrx20091001/item/ee70f7cc6d036d4ea9ba94e0 #ifndef 与 #program once 的区别 为了避免同一个文 ...
- 百度下载google 浏览器安装失败
installer integrity check has failed. Common causes include incomplete download and damaged media co ...
- linxu添加定时任务
1. 在需要定时执行的php文件的第一行加 也就是文件开头加 #! /bin/local/php -q 其中 /bin/local/php 是自己的php.exe 所在的位置 2. 上传要定时执行的 ...
- [LeetCode]题解(python):084-Largest Rectangle in Histogram
题目来源: https://leetcode.com/problems/largest-rectangle-in-histogram/ 题意分析: 给定一个数组,数组的数字代表这个位置上的bar的高度 ...