【动态规划】HDU 1081 & XMU 1031 To the Max
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1081
http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1031
题目大意:
给一个n*n(n<=100)的矩阵,求一个矩形覆盖的值最大是多少。
题目思路:
【动态规划】
二维的最大字段和。先考虑一维的情况。f[i]=max(f[i-1]+a[i],a[i])
只要之前的部分和大于零则一起取一定比只取当前位置的要优。
因此只要判断局部段的和是否大于零。同时每多取一个数就要更新答案。
之后只要将一维扩展到二维就行。枚举行的始末位置。
//
//by coolxxx
//
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define eps (1e-8)
#define J 10000000
#define MAX 0x7f7f7f7f
#define PI 3.1415926535897
#define N 104
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
int f;
char map[N][N];
int tot[N][N];
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j,k,l;
// for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
while(~scanf("%d",&n))
{
ans=-MAX;
for(i=;i<=n;i++)
{
for(j=;j<=n;j++)
{
scanf("%d",&map[i][j]);
tot[i][j]=tot[i-][j]+map[i][j];
}
}
for(l=;l<n;l++)
{
for(i=;i+l<=n;i++)
{
for(j=,f=;j<=n;j++)
{
f+=tot[i+l][j]-tot[i-][j];
ans=max(ans,f);
if(f<)f=;
}
}
}
printf("%d\n",ans);
}
return ;
}
/*
// //
*/
千万不要点
【动态规划】HDU 1081 & XMU 1031 To the Max的更多相关文章
- HDU 1081 To the Max 最大子矩阵(动态规划求最大连续子序列和)
Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...
- HDU 1081 To The Max【dp,思维】
HDU 1081 题意:给定二维矩阵,求数组的子矩阵的元素和最大是多少. 题解:这个相当于求最大连续子序列和的加强版,把一维变成了二维. 先看看一维怎么办的: int getsum() { ; int ...
- HDU 1081 To The Max(动态规划)
题目链接 Problem Description Given a two-dimensional array of positive and negative integers, a sub-rect ...
- (DP)To The Max --HDU -- 1081
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1081 这道题使用到的算法是:预处理+最大连续子串和 如果会做最大连续子串和,那么理解这题就相对简单一些, ...
- hdu 1081 To The Max(dp+化二维为一维)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1081 To The Max Time Limit: 2000/1000 MS (Java/Others ...
- dp - 最大子矩阵和 - HDU 1081 To The Max
To The Max Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=1081 Mean: 求N*N数字矩阵的最大子矩阵和. ana ...
- Hdu 1081 To The Max
To The Max Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- URAL 1146 Maximum Sum & HDU 1081 To The Max (DP)
点我看题目 题意 : 给你一个n*n的矩阵,让你找一个子矩阵要求和最大. 思路 : 这个题都看了好多天了,一直不会做,今天娅楠美女给讲了,要转化成一维的,也就是说每一列存的是前几列的和,也就是说 0 ...
- ACM HDU 1081 To The Max
To The Max Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
随机推荐
- [Angular 2] ng-model and ng-for with Select and Option elements
You can use Select and Option elements in combination with ng-for and ng-model to create mini-forms ...
- [转] Git 分支 - 分支的新建与合并
http://git-scm.com/book/zh/v1/Git-%E5%88%86%E6%94%AF-%E5%88%86%E6%94%AF%E7%9A%84%E6%96%B0%E5%BB%BA%E ...
- 深入探索C++对象模型-1
概述 在实际生产中,遇到一个复杂的类,如果能看出这个类的内存模型结构,那么以后的操作基本就没有难度的: 所以说,学会分析一个类的内存模型,是每一个C++程序员必须要会的知识. 下面,就让我们来了解C+ ...
- http状态码对应表
http状态码 1**:请求收到,继续处理 2**:操作成功收到,分析.接受 3**:完成此请求必须进一步处理 4**:请求包含一个错误语法或不能完成 5**:服务器执行一个完全有效请求失败 100— ...
- CentOS 6.5断电后启动出现:unexpected inconsistency run fsck manully
CentOS 6.5断电后启动出现:unexpected inconsistency run fsck manully 如下图: 解决方法: 1.输入root用户的密码回车: 2.执行以下命令,修复磁 ...
- codevs 1515 跳
/* 画矩阵找规律发现是杨辉三角 Cg (i,j)= C (i+j,i); 贪心走的话 沿着0行(列)一直走然后拐直角 拐弯后每个格子都累加 Cg (n,0) + Cg (n,1) + Cg (n,2 ...
- poj 1201 Interval (查分约束)
/* 数组开大保平安. 查分约束: 输入的时候维护st和end 设每个点取元素di个 维护元素个数前缀和s Sbi-Sai-1>=ci 即:建立一条从ai-1到bi的边 权值为ci 表示ai到b ...
- Asp,题目
1. 简述 private. protected. public. internal 修饰符的访问权限.答 . private : 私有成员, 在类的内部才可以访问. protected : 保护成员 ...
- js 实现关键词球状旋转效果
效果图 html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...
- IMP数据文件时ORA-00959错误分析
有时间模拟一下ORA-00959的测试分析.