POJ 1050(To the Max)
来源:互联网 发布:2010年网络歌曲女 编辑:程序博客网 时间:2024/06/13 23:58
/*** 题意:求最大子矩阵 * 思路:将矩阵看作n行柱形图,其实就是将他 * 转换成一维,然后问题就转换成求最大子段和 * 问题了;* */ #include<stdio.h>#define max(a,b) a>b?a:b#define MIN -10000000#define SIZE 130int num[SIZE][SIZE],n,dp[SIZE][SIZE];int main(){int i,j,k;while(~scanf("%d",&n)){int res=MIN;for(i=1;i<=n;i++)for(j=1;j<=n;j++)scanf("%d",&num[i][j]);for(i=1;i<=n;i++)for(j=1;j<=n;j++)dp[i][j]=num[i][j]+dp[i][j-1];for(i=0;i<n;i++)/**每行子段起点*/for(j=i+1;j<=n;j++)/**每行子段终点*/ { int sum=0,Max=MIN;for(k=1;k<=n;k++){int temp=dp[k][j]-dp[k][i];sum=max(temp,sum+temp);if(sum<0)sum=0;if(Max<sum)Max=sum;}if(Max>res)res=Max;}printf("%d\n",res);}return 0;}
- POJ 1050(To the Max)
- 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 1050 To the Max(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
- poj 1050 To the Max
- poj 1050 To the Max
- Poj 1050 To the Max
- POJ 1050 To the Max
- 最大连续子数列和问题
- Linux 图形界面与命令行模式切换
- 712 - S-Trees
- CodeForces 219D Choosing Capital for Treeland
- 解决.net 2.0以上版本GDI+绘图保存后在Photoshop中无法识别的问题
- POJ 1050(To the Max)
- 两点间最短路径及所有路径
- JavaScript学习笔记,创建对象,属性访问
- uva 10791 - Minimum Sum LCM
- 添加、读取、修改xml例子
- jQuery基础教程之强大的选择器(过滤选择器-基本过滤选择器)
- 备忘录模式(Memento)----行为笔记
- hdoj 2871 Memory Control
- 中断和总线