POJ - 1050 To the Max ...二维最大子矩阵转化为1维
来源:互联网 发布:世纪朝阳证券交易软件 编辑:程序博客网 时间:2024/05/21 09:53
对于1维的问题...用两个下标卡起始位置和结束位置..当这段合>0时..结束位置的下标后移..否则开始下标前移...O(n)的时间复杂度...
此题是2维的情况.....用C(n,2)选择列的上下界.....然后问题就变成了1维的情况...O(n^3)的时间复杂度...
Program:
#include<iostream>#include<stdio.h>#include<string.h>#include<cmath>#include<map>#include<algorithm>#define ll long long#define oo 1000000000using namespace std; int sum[105][105],n;int main(){ int i,j,x,p1,p2,m,ans; memset(sum,0,sizeof(sum)); scanf("%d",&n); for (i=1;i<=n;i++) for (j=1;j<=n;j++) { scanf("%d",&x); sum[i][j]=sum[i-1][j]+x; } ans=-oo; for (i=1;i<=n;i++) for (j=i;j<=n;j++) { p1=p2=1; m=0; while (p2<n) { m+=sum[j][p2]-sum[i-1][p2]; if (m>ans) ans=m; while (m<0 && p1<=p2) { m-=sum[j][p1]-sum[i-1][p1]; p1++; if (p1<=p2 && m>ans) ans=m; } p2++; } } printf("%d\n",ans); return 0;}
- POJ - 1050 To the Max ...二维最大子矩阵转化为1维
- poj 1050To the Max(最大子矩阵和 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(最大子矩阵之和)
- Poj 1050 To the Max (最大子矩阵 DP)
- poj 1050 To the Max(最大子矩阵权值)
- poj 1050 To the Max(最大子矩阵和)
- ACM 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 DP+最大子矩阵和
- C# 9
- 线性模型(1)
- 3I工作室春游活动
- 阿里云
- 新浪微博的JSON解析[转]
- POJ - 1050 To the Max ...二维最大子矩阵转化为1维
- 将字符串中开头和结尾空格去掉,并且中间空格仅仅保留一个
- 让你的APP支持iPhone5
- 694 - The Collatz Sequence
- 静态变量的生存期和作用域
- java面向对象上:java基础语法
- secureCRT 在linux下 有趣的小技巧
- 5月1日将至 你的应用支持iPhone5了吗?还在使用UDID?
- 简单并带有错误的环形单链表检测代码