poj 1050 To the Max && 51nod dp 最大子矩阵和
来源:互联网 发布:apache 配置php7 编辑:程序博客网 时间:2024/05/29 03:54
思路:
我们把每一列第i行到第j行之间的和求出来,形成一个数组c,于是一个第i行到第j行之间的最大子矩阵和对应于这个和数组c的最大子段和。然后每次求数组c的最大子串和,
ACcode:
#include <map>#include <queue>#include <cmath>#include <cstdio>#include <cstring>#include <stdlib.h>#include <iostream>#include <algorithm>#define maxn 700#define ll long longusing namespace std;int n,m;ll dp[maxn][maxn];ll c[maxn];ll ans=0,tmp;int main(){ while(~scanf("%d",&n)){ m=n; for(int i=1;i<=m;++i)for(int j=1;j<=n;++j)scanf("%I64d",&dp[i][j]); memset(c,0,sizeof(c)); for(int i=1;i<=m;++i) for(int j=i;j<=m;++j) for(int k=1,tmp=0;k<=n;++k){ c[k]=(j==i)?dp[i][k]:c[k]+dp[j][k]; if(tmp>0)tmp+=c[k]; else tmp=c[k]; ans=ans>tmp?ans:tmp; } printf("%I64d\n",ans); } return 0;}/*13 6 71 7 5 4 8 3 91 4 3 5 6 2 8 9*/
0 0
- poj 1050 To the Max && 51nod dp 最大子矩阵和
- [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 最大子矩阵和
- 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 -- 最大子矩阵和
- github代码上传(初学)
- Property Animation(属性动画)
- Css技术入门笔记01
- Amazon : 找出所给数字的下一个回文数
- Android系统中Parcelable和Serializable的区别
- poj 1050 To the Max && 51nod dp 最大子矩阵和
- 【翻译】Itti的论文1998 A Model of Saliency-Based Visual Attention
- 2016"百度之星" - 资格赛(Astar Round1) C
- linux下快速根据文件内容查找文件
- 常用效果集绵
- 分类作用
- c语言编写猜数字游戏
- 蓝桥杯练习题 BASIC-27 2n皇后问题(八皇后问题 搜索)
- 《快学Scala》第三章习题解答