题目链接:

  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. Tcpdump命令行 与 GUI Wireshark

    http://www.cnblogs.com/ggjucheng/archive/2012/01/14/2322659.html tcpdump host 192.168.1.26 and \(192 ...

  2. ios中xib的使用介绍

    ios中Xib的使用 ios中xib的使用 Nib files are the quintessential(典型的) resource type used to create iOS and Mac ...

  3. mac eclipse配置 tomcat

    mac由于各种软件不兼容,某些软件对于开发来说很苦恼,tomcat这个东西一直不知道怎么弄,项目都开了好几天了,一直用在虚拟机上用windows系统,但是用虚拟机明显感觉到电池待机时间更短了,所以就研 ...

  4. AutoBackupForApps

    This sample demonstrates how to selectively disable Automatic Backups in Android M, either by adjust ...

  5. html.ex.day01

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. Struts2 删除后直接直接到List显示页面

    package com.sun; import java.util.List; import java.util.Map; import org.hibernate.Session; import o ...

  7. (转)PHP的ereg()与eregi()的不同及相同点。对比

    ereg() 字符串比对解析. 语法: int ereg(string pattern, string string, array [regs]); 返回值: 整数/数组 函数种类: 资料处理 内容说 ...

  8. 详解Linux服务器最大tcp连接数

    网络编程在tcp应用中,server事先在某个固定端口监听,client主动发起连接,经过三路握手后建立tcp连接.那么对单机,其最大并发tcp连接数是多少? 如何标识一个TCP连接在确定最大连接数之 ...

  9. WPF Binding

    winform有binding, WPF也有binding,区别在哪呢?这里暂时不提.以前也检查接触WPF binding, 但为什么过段时间就忘记了呢? 可能主要原因自己的知识体系不够完善吧,下面我 ...

  10. TalkingDataGame SDK在android Lua上的使用

    千呼万唤使出来...终于开始更新lua版本的内容了,之前一直有这方面的计划,由于公司业务比较多,一直比较忙-见谅.. 费话不多说,直接上内容.. 整体来讲,先是先建议看一下之前关于cocos2dx上的 ...