poj 1050 To the Max dp 最大子矩阵
来源:互联网 发布:微商和淘宝哪个可靠 编辑:程序博客网 时间:2024/05/14 12:51
题目
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=105944#problem/B
题目来源:2016寒假高年训练3
简要题意:求出最大子矩阵
题解
经典的模型,需要好好理解掌握。
dp的做法就是先预处理出每行前缀。
枚举矩阵的左右边界,然后纵向做最大子段和。
整个复杂度是
Θ(n3) 的。最大子段就是保存以每位为结尾的最大值,转移就是前面一格为负数就取自身,否则加上前一个的dp更新自身。
代码
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <stack>#include <queue>#include <string>#include <vector>#include <set>#include <map>#define pb push_back#define mp make_pair#define all(x) (x).begin(),(x).end()#define sz(x) ((int)(x).size())#define fi first#define se secondusing namespace std;typedef long long LL;typedef vector<int> VI;typedef pair<int,int> PII;// headconst int N = 105;int a[N][N];int main() { int n; while (scanf("%d", &n) == 1) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { scanf("%d", a[i]+j); a[i][j] += a[i][j-1]; } } int ans = -2e9; for (int l = 1; l <= n; l++) { for (int r = l; r <= n; r++) { int sum = 0; for (int i = 1; i <= n; i++) { int cur = a[i][r] - a[i][l-1]; sum = (sum < 0) ? cur : sum + cur; ans = max(ans, sum); } } } printf("%d\n", ans); } return 0;}
0 0
- Poj 1050 To the Max (最大子矩阵 DP)
- [POJ 1050] To the Max DP+最大子矩阵和
- poj 1050 To the Max dp 最大子矩阵
- POJ 1050 To the Max(dp 最大子矩阵和/最大子段和问题)
- poj 1050To the Max(最大子矩阵和 DP 二维)
- hdu 1081 To The Max ****poj 1050(最大子矩阵和)DP
- POJ 1050 To the Max 最大子矩阵和 简单dp
- POJ 1050 To the Max(DP,最大子矩阵和)
- poj To the Max 1050 (二维最大子矩阵 DP)
- poj 1050 To the Max && 51nod dp 最大子矩阵和
- poj to the max(最大子矩阵和) 1050(dp大法)
- POJ 1050 To the max 最大子矩阵
- poj 1050 To the Max 最大子矩阵和
- POJ 1050 to the max最大子矩阵
- poj 1050 To the Max(最大子矩阵和)
- poj 1050 To the Max(最大子矩阵之和)
- poj 1050 To the Max(最大子矩阵权值)
- poj 1050 To the Max(最大子矩阵和)
- hibernate 搭建junit日志环境
- 优化sql语句执行效率的方法
- 其他IO流
- LeetCode OJ 2.Add Two Numbers
- 大型网站架构系列:负载均衡详解(3)
- poj 1050 To the Max dp 最大子矩阵
- Hadoop安装教4程_单机/伪分布式配置_Hadoop2.6.0/Ubuntu14.0
- 文本分类算法之--BP神经网络
- LeetCode OJ 3.Longest Substring Without Repeating Characters
- HDU 1054 最小顶点覆盖 (树形dp)
- servlet实现文件上传
- Android设备的内置存储和外置存储到底是怎么回事,深入理解
- Windbg断点调试
- 【Manthan, Codefest 16A】【水题 暴力】Ebony and Ivory ax+by=z