POJ 1050 To the Max 暴力,基础知识 难度:0
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的更多相关文章
- POJ 1050 To the Max 最大子矩阵和(二维的最大字段和)
传送门: http://poj.org/problem?id=1050 To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submi ...
- poj 1050 To the Max(最大子矩阵之和)
http://poj.org/problem?id=1050 我们已经知道求最大子段和的dp算法 参考here 也可参考编程之美有关最大子矩阵和部分. 然后将这个扩大到二维就是这道题.顺便说一下,有 ...
- poj 1050 To the Max(最大子矩阵之和,基础DP题)
To the Max Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 38573Accepted: 20350 Descriptio ...
- POJ 1050 To the Max -- 动态规划
题目地址:http://poj.org/problem?id=1050 Description Given a two-dimensional array of positive and negati ...
- poj 1050 To the Max (简单dp)
题目链接:http://poj.org/problem?id=1050 #include<cstdio> #include<cstring> #include<iostr ...
- poj 1050 To the Max(线性dp)
题目链接:http://poj.org/problem?id=1050 思路分析: 该题目为经典的最大子矩阵和问题,属于线性dp问题:最大子矩阵为最大连续子段和的推广情况,最大连续子段和为一维问题,而 ...
- poj - 1050 - To the Max(dp)
题意:一个N * N的矩阵,求子矩阵的最大和(N <= 100, -127 <= 矩阵元素 <= 127). 题目链接:http://poj.org/problem?id=1050 ...
- [ACM_动态规划] POJ 1050 To the Max ( 动态规划 二维 最大连续和 最大子矩阵)
Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...
- poj 1050 To the Max
To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 45906 Accepted: 24276 Desc ...
随机推荐
- Joke
你忍心蜗居在不到10平米的小屋里吗?你忍心看着自己的女友和你奋斗一辈子还供不起一套房吗?你忍心看着你父母缩衣节食把仅有的一点养老金帮你还房贷吗? 这里才是实现你梦想的地方.加入我们,待遇从优,装备齐全 ...
- linux rwxrwxrwt文件夹属性
/tmp 的permission是rwxrwxrwt chmod 0777 /abc rwxrwxrwx chmod 777 /abc rwxrwxrwx chmod 17 ...
- IIS_Mvc发布
网站发布步骤: 这部分是转载文章 在此标明出处,以前有文章是转的没标明的请谅解,因为有些已经无法找到出处,或者与其它原因. 如有冒犯请联系本人,或删除,或标明出处. 因为好的文章,以前只想收藏,但连接 ...
- Hadoop的HA集群启动和停止流程
假设我们有3台虚拟机,主机名分别是hadoop01.hadoop02和hadoop03. 这3台虚拟机的Hadoop的HA集群部署计划如下: 3台虚拟机的Hadoop的HA集群部署计划 hadoop0 ...
- jQuery内置函数 ready
jQuery给我们提供了一些非常实用的函数 ready:加载函数 传统事件只能绑定一个函数 后面的函数会把前面的函数覆盖 js中用的是 window.onload = function(){}; j ...
- table和div设置height:100%无效的完美解决方法
刚接触网页排版的新手,常出现这种情况:设置table和div的高height="100%"无效,使用CSS来设置height:"100%"也无效,为什么会这样呢 ...
- phalcon: router规则与解析,已经生成router的链接地址
本人采用的是假分模块(目录),通过命名空间来进行模块分组的,非官方分组,所以在router是都会加上 namespace 信息,你也可适当的参考: 前提: /** * 注册命名空间 */ $loade ...
- 比对工具之 BWA 使用方法
BWA算法简介: BWA-bactrack BWA-SW BWA-MEM BWA安装: # installing BWA .tar.bz2 -C /opt/biosoft/ cd /opt/bioso ...
- Android 应用开发耗电量控制。。
当程序启动手机越多的模块,那耗电就越快 当你的程序运行时只占用CPU的时候,这时候耗电量是最少的. 当然这时候如果cpu的运行速度很慢那是最好的.. 程序耗电量控制首要从下面3个方面抓起: 1.频繁的 ...
- 【CodeForces 651A】Joysticks 模拟
题意:给定a,b,每个单位时间可以将a,b中一台加1,一台减2,求最久可以支持多久. #include <cstdio> #include <algorithm> using ...