http://poj.org/problem?id=1050

设sum[i][j]为从(1,1)到(i,j)的矩形中所有数字之和

首先处理出sum[i][j],此时左上角为(x1,y1),右下角为(x2,y2)的矩形中所有数字之和就是sum[x2][y2]-sum[x1][y2]-sum[x2][y1]+sum[x1][y1]

因为n<100,在不需要优化的边上,所以就直接暴力了

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e2+;
double e[maxn];
int match[maxn];
int n,m;
int sum[maxn][maxn],maz[maxn][maxn];
int main()
{
scanf("%d",&n);
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
scanf("%d",maz[i]+j);
sum[i][j]=sum[i][j-]+sum[i-][j]-sum[i-][j-]+maz[i][j];
}
}
int ans=-0x7fffffff;
for(int x1=;x1<=n;x1++){
for(int y1=;y1<=n;y1++){
for(int x2=x1+;x2<=n;x2++){
for(int y2=y1+;y2<=n;y2++){
ans=max(ans,sum[x2][y2]-sum[x1][y2]-sum[x2][y1]+sum[x1][y1]);
}
}
}
}
printf("%d\n",ans); return ;
}

POJ 1050 To the Max 暴力,基础知识 难度:0的更多相关文章

  1. POJ 1050 To the Max 最大子矩阵和(二维的最大字段和)

    传送门: http://poj.org/problem?id=1050 To the Max Time Limit: 1000MS   Memory Limit: 10000K Total Submi ...

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

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

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

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

  4. POJ 1050 To the Max -- 动态规划

    题目地址:http://poj.org/problem?id=1050 Description Given a two-dimensional array of positive and negati ...

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

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

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

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

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

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

  8. [ACM_动态规划] POJ 1050 To the Max ( 动态规划 二维 最大连续和 最大子矩阵)

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

  9. poj 1050 To the Max

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

随机推荐

  1. bootstrap学习笔记<五>(表单一)

    表单 bootstrap为表单提供三种样式:默认表单,水平表单,内联表单. <form class="form-horizontal" role="form&quo ...

  2. misc设备

    WatchDog Timer驱动 混杂设备 Misc(或miscellaneous)驱动是一些拥有着共同特性的简单字符设备驱动.内核抽象出这些特性而形成一些API(在文件drivers/char/mi ...

  3. 我想有个梦想(I want have a dream)

    成东青说过:梦想是什么,梦想就是你坚持就觉得是幸福东西. 多好啊,有梦想,想想就觉得幸福的.也许你会觉得有点做作,但我真觉得是这样.没有梦想就像一个没有了灵魂的躯壳,整天浑浑噩噩,整天麻木的上班下班, ...

  4. python操作postgresql数据库

    import psycopg2 conn = psycopg2.connect(database=") cur = conn.cursor() cur.execute("CREAT ...

  5. 集群--LVS的DR模型配置

    1.查看内核是否有IPVS内核模块 grep -i 'ip_vs' /boot/config-2.6.32-431.el6.x86_64

  6. svn提交代码的原则

    [1]先更新在提交 [2]多提交 [3]不要提交不能通过编译的代码 [4]每次提交必须书写明晰的标注 [5]提交时注意不要提交本地自动生成的文件 [6]不要提交自己不明白的代码 [7]慎用锁定功能

  7. NYOJ 298 点的变换

    题目链接:298 点的变换 这题放在矩阵快速幂里,我一开始想不透它是怎么和矩阵搭上边的,然后写了个暴力的果然超时,上网看了题解后,发现竟然能够构造一些精巧的矩阵来处理,不得不说实在太强大了! http ...

  8. JS获取用户控件中的子控件Id

    用户控件 <asp:HiddenField ID="hfGradeId" runat="server" /> <asp:HiddenField ...

  9. eclipse插件安装 (zhuan)

    https://my.oschina.net/gxs2012/blog/205875 http://blog.csdn.net/zhujiaxing666666/article/details/150 ...

  10. Freemarker 入门示例(zhuan)

    http://cuisuqiang.iteye.com/blog/2031768 ************************************ 初步学习freemarker ,先做一个简单 ...