题目链接:

  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的更多相关文章

  1. HDU 1081 To the Max 最大子矩阵(动态规划求最大连续子序列和)

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

  2. HDU 1081 To The Max【dp,思维】

    HDU 1081 题意:给定二维矩阵,求数组的子矩阵的元素和最大是多少. 题解:这个相当于求最大连续子序列和的加强版,把一维变成了二维. 先看看一维怎么办的: int getsum() { ; int ...

  3. HDU 1081 To The Max(动态规划)

    题目链接 Problem Description Given a two-dimensional array of positive and negative integers, a sub-rect ...

  4. (DP)To The Max --HDU -- 1081

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1081 这道题使用到的算法是:预处理+最大连续子串和 如果会做最大连续子串和,那么理解这题就相对简单一些, ...

  5. 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 ...

  6. 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 ...

  7. Hdu 1081 To The Max

    To The Max Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  8. URAL 1146 Maximum Sum & HDU 1081 To The Max (DP)

    点我看题目 题意 : 给你一个n*n的矩阵,让你找一个子矩阵要求和最大. 思路 : 这个题都看了好多天了,一直不会做,今天娅楠美女给讲了,要转化成一维的,也就是说每一列存的是前几列的和,也就是说 0 ...

  9. ACM HDU 1081 To The Max

     To The Max Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

随机推荐

  1. [转] 剖析 epoll ET/LT 触发方式的性能差异误解(定性分析)

    http://blog.chinaunix.net/uid-17299695-id-3059078.html PS:Select和Poll都是水平触发,epoll默认也是水平触发 ET模式仅当状态发生 ...

  2. Android(java)学习笔记228:服务(service)之绑定服务调用服务里面的方法

    1.绑定服务调用服务里面的方法,图解: 步骤: (1)在Activity代码里面绑定 bindService(),以bind的方式开启服务 :                     bindServ ...

  3. vim 设定一个新的snippets

    目录 ~/.vim/bundle/vim-snippets/snippets 编辑 _.snippets 在最后添加一行自己需要的,比如想要个自己的名字,然后按tab,即出现全称,可以添加如下内容 s ...

  4. python----------反射和设计模式

    反射: 把字符串映动态射成对象内存地址. hasattr():判断一个对象里是否有对应的字符串的方法 getattr():根据字符串去获取obj对象里的对应方法的内存地址. class Dog(obj ...

  5. Python 时间函数

    时间的运用 #coding=utf-8 #!user/bin/python import time import calendar ticks = time.asctime(time.localtim ...

  6. Effective java-枚举和注解思维导图

  7. 佛祖保佑 永无BUG(网转 by atkfc)

        //                   _ooOoo_    //                  o8888888o    //                  88" . ...

  8. C#部分方法定义

    C#部分方法定义 部分类也可以定义部分方法.部分方法在部分类中定义,但没有方法体,在另一个部分类中执行.在这两个部分类中,都要使用partial关键字. public partial class My ...

  9. 【转】 iOS开发数据库篇—SQLite简单介绍

    开始学SQLite啦, 原文: http://www.cnblogs.com/wendingding/p/3868893.html iOS开发数据库篇—SQLite简单介绍 一.离线缓存 在项目开发中 ...

  10. codevs 1139 观光公交

    #include<cstdio> #include<cstdlib> #include<cstring> #define max(a,b) (a > b ? ...