poj 1050 To the Max
来源:互联网 发布:网络速度测试工具 编辑:程序博客网 时间:2024/05/21 09:22
题目大意:有一个n*n的二维矩阵,求出最大子矩阵的和。
思路:
(1)对于一维数列a1,a2,a3,a4,......,an,以第i个数结尾的字段和dp[i] = num[i] + max(dp[i-1], 0)
(2)对于二维矩阵,枚举不同的列,然后视为一维数列求最大字段和的问题。
#include <iostream>#include <cstdio>#include <climits>using namespace std;int map[105][105],dp[105];int main(){ int n,i,j,k,tmp,ans; while (scanf("%d",&n)==1) { for (i=1;i<=n;i++) for (j=1;j<=n;j++) { scanf("%d",&tmp); map[i][j]=map[i][j-1]+tmp; } ans=INT_MIN; for (i=1;i<=n;i++) for (j=i;j<=n;j++) for (k=1;k<=n;k++) { dp[k]=map[k][j]-map[k][i-1]+max(0,dp[k-1]); ans=max(ans,dp[k]); } printf("%d\n",ans); } return 0;}
- 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
- 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
- 使用Ajax ModalPopupExtender解决假死问题
- 【ASP.net文档】用C#实现HTTP协议下的多线程文件传输
- [Android开发]有关Android线程的学习
- Linux内核I2C子系统驱动(一)
- 二级联动
- poj 1050 To the Max
- 将ListView控件中的数据导出到Excel文
- Linux内核I2C子系统驱动(二)
- Linux内核I2C子系统驱动(三)
- 编写iptables模块实现不连续IP地址的DNAT-POOL
- 唐骏常出三道微软面试题
- jsp中tomcat部署实现外网访问
- 使用VIM将一行X509证书分解为多行的方式
- Asp.net导出Excel(三)