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 ...
随机推荐
- iOS 设置button中图文位置
方法一. -(CGRect)imageRectForContentRect:(CGRect)contentRect { return CGRectMake(self.width - kImage ...
- Corelocation及地图控件学习笔记
Corelocation基本使用 在地图章节的学习中,首先要学的便是用户位置定位,因此我们首先要掌握Corelocation的使用.(在IOS8以前可以系统会直接请求授权,现在需要我们自己调用方式通知 ...
- 【转载】Spark系列之运行原理和架构
参考 http://www.cnblogs.com/shishanyuan/p/4721326.html 1. Spark运行架构 1.1 术语定义 lApplication:Spark Applic ...
- Android手机分辨率基础知识(DPI,DIP计算)二
dp = dip : device independent pixels(设备独立像素). 不同设备有不同的显示效果,这个和设备硬件有关,一般我们为了支持WVGA.HVGA和QVGA 推荐使用这个,不 ...
- 基础2 JVM
1. 内存模型以及分区,需要详细到每个区放什么. //运行时数据区域 方法区 Method Area 各个线程共享的内存区域 存储已被虚拟机加载的类信息 常量 静态变量 即时编译器编译后的代码 虚拟机 ...
- Subversion中文手册(svnbook) TortoiseSVN中文帮助手册
文档地址 http://svndoc.iusesvn.com/
- SciTE 文本编辑器
个人一直使用,强大,轻型基于 Scintilla. http://www.scintilla.org/SciTEDownload.html 解压缩后,能右键文件打开 修改注册表, 使能资源管理器 右键 ...
- armp启动
1.启动apahcehttpd.exe -k starthttpd.exe -k restart 重启httpd.exe -k install 安装 2.php启动apache.conf文件添加:Lo ...
- PC上安装多个操作系统
目 录 第1章 绪论 1 1.1 目标 1 1.2 适宜的读者 1 第2章 制作启动U盘 2 2.1 初级安装 2 2.2 启动分析 3 2.3 高级安装 1 ...
- h5新增标签兼容性
<address> 标签定义文档或文章的作者/拥有者的联系信息. 兼容所有浏览器 <area> 标签定义图像映射中的区域(注:图像映射指得是带有可点击区域的图像).兼容所有浏 ...