[POJ1050]To the Max(最大子矩阵,DP)
题目链接:http://poj.org/problem?id=1050
发现这个题没有写过题解,现在补上吧,思路挺经典的。
思路就是枚举所有的连续的连续的行,比如1 2 3 4 12 23 34 45 123 234 345...然后把这些行对应列相加缩成一行,之后就是求最大子序列和了。
/*
━━━━━┒ギリギリ♂ eye!
┓┏┓┏┓┃キリキリ♂ mind!
┛┗┛┗┛┃\○/
┓┏┓┏┓┃ /
┛┗┛┗┛┃ノ)
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┃┃┃┃┃┃
┻┻┻┻┻┻
*/
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%lld", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f7f, sizeof(a))
#define lrt rt << 1
#define rrt rt << 1 | 1
#define pi 3.14159265359
#define RT return
#define lowbit(x) x & (-x)
#define onenum(x) __builtin_popcount(x)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<LL, LL> pll;
typedef map<string, int> msi;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb; const int maxn = ;
int G[maxn][maxn];
int n;
int dp[maxn]; int lss() {
int tmp = -0x7f7f7f, ret = -0x7f7f7f;
For(i, , n+) {
if(tmp > ) tmp += dp[i];
else tmp = dp[i];
ret = max(tmp, ret);
}
return ret;
} int main() {
// FRead();
while(~Rint(n)) {
For(i, , n+) For(j, , n+) Rint(G[i][j]);
int ret = ;
For(i, , n+) {
Cls(dp);
For(j, i, n+) {
For(k, , n+) dp[k] += G[j][k];
ret = max(ret, lss());
}
}
printf("%d\n", ret);
}
RT ;
}
[POJ1050]To the Max(最大子矩阵,DP)的更多相关文章
- POJ1050 To the Max 最大子矩阵
POJ1050 给定一个矩阵,求和最大的子矩阵. 将每一列的值进行累加,枚举起始行和结束行,然后就可以线性优化了 复杂度O(n^3) #include<cstdio> #include&l ...
- poj1050 To the Max(降维dp)
To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 49351 Accepted: 26142 Desc ...
- [POJ1050]To the Max
[POJ1050]To the Max 试题描述 Given a two-dimensional array of positive and negative integers, a sub-rect ...
- HDU 1003 Max Sum --- 经典DP
HDU 1003 相关链接 HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...
- (线性dp 最大子段和 最大子矩阵和)POJ1050 To the Max
To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 54338 Accepted: 28752 Desc ...
- poj 1050 To the Max(最大子矩阵之和,基础DP题)
To the Max Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 38573Accepted: 20350 Descriptio ...
- poj 1050 To the Max 最大子矩阵和 经典dp
To the Max Description Given a two-dimensional array of positive and negative integers, a sub-rect ...
- BZOJ 1084: [SCOI2005]最大子矩阵 DP
1084: [SCOI2005]最大子矩阵 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=1084 Description 这里有一个n* ...
- ZOJ1074 (最大和子矩阵 DP)
F - 最大子矩阵和 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Descri ...
随机推荐
- 【HDOJ】【3068】最长回文
Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...
- ZOJ Monthly, July 2015
B http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5552 输入n,表示有n个数1到n.A先拿,B后拿,依次拿,每次可以拿任意一 ...
- 0910 noip模拟
教师节快乐: T1:勇士闯魔塔,是一道很裸的莫队题目,但在老师的催促下,出题人@syq同学修改了第一题,使之成了一道送分题,全暴力水过: T2:第二题是一道预处理+分组背包,考试中,忘了分组背包怎么敲 ...
- JS This关键字
http://www.ruanyifeng.com/blog/2010/04/using_this_keyword_in_javascript.html http://www.cnblogs.com/ ...
- 遭遇Asp.Net长文件名下载的问题和解决办法
在Asp.Net中写了一个附件上传和下载的程序,附件上传到数据库中,然后将附件的GUID保存起来,我们可以根据GUID来找到数据库中的附件,一般附件下载的代码是: <!--<br /> ...
- javascript实现数据结构与算法系列:栈 -- 顺序存储表示和链式表示及示例
栈(Stack)是限定仅在表尾进行插入或删除操作的线性表.表尾为栈顶(top),表头为栈底(bottom),不含元素的空表为空栈. 栈又称为后进先出(last in first out)的线性表. 堆 ...
- 哪些问题困扰着我们?DevOps 使用建议
[编者按]随着 DevOps 被欲来越多机构采用,一些共性的问题也暴露出来.近日,Joe Yankel在「Devops Q&A: Frequently Asked Questions」一文中总 ...
- windbg内核诊断方式--转载
一.WinDbg是什么?它能做什么? WinDbg是在windows平台下,强大的用户态和内核态调试工具.它能够通过dmp文件轻松的定位到问题根源,可用于分析蓝屏.程序崩溃(IE崩溃)原因,是我们日常 ...
- 评论 ”[实例] 设计基于JQM的WebApp“
点这里 DEMO 先上最近做的一个WebApp小应用,http://iwxy.me/m.html,大家可以先去玩玩儿,在移动终端访问查看最佳效果 实现的功能是微博上偶然看到的一个小测试,动物认识真实的 ...
- sparksql链接mysql
1.在IDEA上建立一个sparksql_mysql的scala对象. 2.连接mysql的代码如下 import java.sql.{DriverManager, PreparedStatement ...