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 ...
随机推荐
- Nexus4_文件名乱码
1. 官方的出厂映像 for Android4.4:occam-krt16s-factory-2006f418.tgz 2. 自己编译的 Android-4.4_r1 (AOSP on Mako) 映 ...
- SQL 总结
1. select 使用正则表达式 正则表达式的模式串, 与linux基本相同, oracle提供以下4个函数来支持正则表达式: REGEXP_LIKE: 比较一个字符串是否与正则表达式匹配(看来是返 ...
- poj2540Hotter Colder(半平面交)
链接 根据距离可以列得直线方程,附上初始矩形的四个顶点,依次用直线切割. #include<iostream> #include <stdio.h> #include < ...
- Spring Bean配置默认为单实例 pring Bean生命周期
Bean默认的是单例的. 如果不想单例需要如下配置:<bean id="user" class="..." scope="singleton&q ...
- C++常量(C++数值常量、字符串常量、符号常量)
http://see.xidian.edu.cn/cpp/biancheng/view/104.html 字符串常量 用双撇号括起来的部分就是字符串常量,如"abc"," ...
- 转!!Java 基础面试题的剖析: short s1=1;s1 = s1 +1 报错? s1+=1 呢
short s1=1;s1 = s1 +1会报错吗? package common; public class ShortTypeTest { /* * @param args */ publi ...
- 20160805_CentOS6_控制台切换
1. Ctrl + Alt + F1~F6 Ctrl + Alt + F1 是 图形界面(如果装了的话),后面的是 控制台界面 2. 3.
- tabhost切换标签:Log中出现You must supply a layout_width attribute的解决方法
谷歌.百度该问题,发现,除非是真的忘记添加layout_height或者layout_width属性值,对于布局文件没有语法问题但又难以发现问题所在的情况,从自己的经历和一个帖子的说明看到,该错误多半 ...
- C/C++中堆与栈
本文介绍C/C++中堆,栈及静态数据区. 五大内存分区 在C++中,内存分成5个区,他们分别是堆.栈.自由存储区.全局/静态存储区和常量存储区.下面分别来介绍: 栈,就是那些由编译器在需要的时候分 ...
- [bootstrap] 栅格系统和布局
1.简介 栅格系统(grid systems),也称为“网格系统”,运用固定的格子设计版面布局,风格工整简洁.是从平面栅格系统演变而来. Bootstrap建立在12列栅格系统.布局.组件之上.以规则 ...