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

 // 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. linux yum 命令 详解

    linux yum命令详解 yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器.基於RPM包管理,能 ...

  2. 在iptables防火墙下开启vsftpd的端口

    在开启vsftpd端口后发现用客户端工具能登陆,但无法浏览文件和新建文件.此时看了一下ftp的协议,发现ftp有主动模式和被动模式.在服务端开21端口是让客户端进来,并没有出去的端口,还在服务端开启出 ...

  3. 如何说服你的老板必须使用APM?

    APM研究院 2015/04/24 16:56 2013年,某权威机构提供一组数据显示:亚马逊每100毫秒延迟会使销售额下降1%:雅虎一秒钟服务器延迟导致收入下降2.8%:谷歌搜索结果页面放缓100毫 ...

  4. POJ 1547

    #include<iostream> #include<string> using namespace std; int main() { int length; int hi ...

  5. HDU 1016 Prime Ring Problem (素数筛+DFS)

    题目链接 题意 : 就是把n个数安排在环上,要求每两个相邻的数之和一定是素数,第一个数一定是1.输出所有可能的排列. 思路 : 先打个素数表.然后循环去搜..... #include <cstd ...

  6. 20款最受欢迎的HTML5游戏引擎收集

    在“最火HTML5 JavaScript游戏引擎”系列文章国外篇(一)中,我们盘点了当下备受开发者推崇的非国产HTML5和JavaScript游戏引擎.在各种2D小游戏逆袭的今天,用HTML5和Jav ...

  7. 编程实现linux下的shell

    /************************************************************************* > File Name: Kris_shel ...

  8. ida GDB 远程调试

    在看雪上回答的问题,有人问在WinDbg下断KiDebugRoutine或者KdEnterDebugger函数会引发蓝屏!因为是在调试Windows的内核调试引擎,我给出的解决办法是用不依赖Windo ...

  9. Linux进程调度原理

    Linux进程调度原理 Linux进程调度机制 Linux进程调度的目标 1.高效性:高效意味着在相同的时间下要完成更多的任务.调度程序会被频繁的执行,所以调度程序要尽可能的高效: 2.加强交互性能: ...

  10. mq_getattr

    NAME mq_getattr - 获取消息队列的属性(REALTIME) SYNOPSIS #include <mqueue.h> int mq_getattr(mqd_t mqdes, ...