最大子矩阵和。类似于子序列最大和。

 // File Name: 1050.cpp
// Author: Missa_Chen
// Created Time: 2013年06月22日 星期六 17时06分39秒 #include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <cstdlib> using namespace std; #define LL long long
const int inf = 0x3f3f3f3f;
const int maxn = ;
int n;
int sum[maxn][maxn];
int main()
{
while (~scanf("%d",&n))
{
for (int i = ; i <= n; ++i)
for (int j = ; j <= n; ++j)
scanf("%d", &sum[i][j]);
for (int i = ; i <= n; ++i)
sum[i][] = ;
for (int i = ; i <= n; ++i)
for (int j = ; j <= n; ++j)
sum[i][j] += sum[i][j - ];
int ans = -inf;
for (int i = ; i <= n; ++i)
for (int j = i; j <= n; ++j)
{
int tmp = -inf;
for (int k = ; k <= n; ++k)
{
if (tmp >= )
tmp += (sum[k][j] - sum[k][i - ]);
else
tmp = sum[k][j] - sum[k][i - ];
ans = max(ans, tmp);
}
}
printf("%d\n", ans);
}
return ;
}

poj 1050(DP)的更多相关文章

  1. poj 1050 To the Max(最大子矩阵之和)

    http://poj.org/problem?id=1050 我们已经知道求最大子段和的dp算法 参考here  也可参考编程之美有关最大子矩阵和部分. 然后将这个扩大到二维就是这道题.顺便说一下,有 ...

  2. poj 1050 To the Max (简单dp)

    题目链接:http://poj.org/problem?id=1050 #include<cstdio> #include<cstring> #include<iostr ...

  3. poj 1050 To the Max(线性dp)

    题目链接:http://poj.org/problem?id=1050 思路分析: 该题目为经典的最大子矩阵和问题,属于线性dp问题:最大子矩阵为最大连续子段和的推广情况,最大连续子段和为一维问题,而 ...

  4. poj - 1050 - To the Max(dp)

    题意:一个N * N的矩阵,求子矩阵的最大和(N <= 100, -127 <= 矩阵元素 <= 127). 题目链接:http://poj.org/problem?id=1050 ...

  5. poj 1050 To the Max 最大子矩阵和 经典dp

    To the Max   Description Given a two-dimensional array of positive and negative integers, a sub-rect ...

  6. poj 1050(矩阵求和问题dp)

    To the Max Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44765   Accepted: 23700 Desc ...

  7. [poj]1050 To the Max dp

    Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...

  8. poj 1050 To the Max(最大子矩阵之和,基础DP题)

    To the Max Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 38573Accepted: 20350 Descriptio ...

  9. 简单DP+暴力 POJ 1050

    To the Max Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 45915   Accepted: 24282 Desc ...

随机推荐

  1. 国内Jquery CDN

    新浪CDN: <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js">< ...

  2. ASP.NET 4.5新特性WebAPI从入门到精通

    在新出的MVC4中,增加了WebAPI,用于提供REST风格的WebService,新生成的WebAPI项目和典型的MVC项目一样,包含主要的Models.Views.Controllers等文件夹和 ...

  3. DB2学习

    1.为了使用ORG_ID,由于OCRM_F_MM_MKT_PLAN a 没有ORG_ID,但是OCRM_F_MM_EXECUTE_INST_DESC d 表里面有,可以使a表连接b表,创建临时表t. ...

  4. Javascript 数组循环遍历之forEach

    1.  js 数组循环遍历. 数组循环变量,最先想到的就是 for(var i=0;i<count;i++)这样的方式了. 除此之外,也可以使用较简便的forEach 方式   2.  forE ...

  5. hadoop 2.0 native

    1.安装protobuf,参照http://wiki.apache.org/hadoop/HowToContribute 安装java模块 在java目录mvn install 2.配置protobu ...

  6. 华为上机:Tom的生日礼物

    Tom的生日礼物 描述: 四月一日快到了,Tom想了个愚人的好办法——送礼物.嘿嘿,不要想的太好,这礼物可没那么简单,Tom为了愚人,准备了一堆盒子,其中有一个盒子里面装了礼物.盒子里面可以再放零个或 ...

  7. How to say "no"?

    How to say "no"?7招教你如何拒绝别人      Do you have a hard time saying no to others? Do you say “y ...

  8. jsp中如何用jstl实现if(){}else if(){}else{}

    <c:choose> <c:when test="${条件}"> 情况1........... </c:when> <c:when tes ...

  9. VS2010/MFC编程入门之三(VS2010应用程序工程中文件的组成结构)

    VS2010/MFC编程入门之三(VS2010应用程序工程中文件的组成结构)-软件开发-鸡啄米 http://www.jizhuomi.com/software/143.html   鸡啄米在上一讲中 ...

  10. Android应用截图和SurfaceView截图问题总结

          最近在做android截图应用的过程遇到很多问题,接触了好些截图方法,但是还是不能实现SufaceView截图功能.今天就把我尝试过的方法总结下,希望把我惨痛的经历写出来后能够帮助到要做此 ...