【动态规划】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 ...
随机推荐
- Scriptcase演示程序
为了方便大家对Scriptcase有一个非常直观的印象,现在将Scriptcase的示例程序进行了适当汉化,并且放在互联网上,您可以直接点击这个地址访问. 需要说明的是,示例程序中提供的范例,基本上都 ...
- [CSS3] Using CSS Combinators to Identify Siblings and Descendants in CSS
CSS combinators allows us to reference the DOM relationship between two or more elements in CSS. < ...
- 解除网页右键限制和开启网页编辑状态的js代码
当访问页面右键被限制了怎么办?很好办!将以下代码添加进收藏夹,点击执行即可: javascript:alert(document.onselectstart = document.onbeforeco ...
- 教学项目之-通过Python实现简单的计算器
教学项目之-通过Python实现简单的计算器 计算器开发需求 实现加减乘除及拓号优先级解析 用户输入 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/ ...
- My way to Python - Day05 - 面向对象
思维导图
- android中获取时间
android中获取时间 1)通过calendar类获取 Calendar calendar = Calendar.getInstance();int moth = calendar.get(Cale ...
- Linux编程之定制带级别的log
我的开发组长曾经说过这么一段话"一个优秀的程序员不在于他写代码有多快,也不在于他能不能实现这个模块的功能,要实现业务实现功能谁不会啊,重要的是他的解决能力,也就说当程序出现错误时你能不能够快 ...
- C#解leetcode 16. 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...
- nodejs抓取网页内容
function loadPage(url) { var http = require('http'); var pm = new Promise(function (resolve, reject) ...
- java常见错误的列表
ava常见错误列表: 找不到符号(symbol) 类X是public的,应该被声明在名为X.java的文件中 缺失类.接口或枚举类型 缺失X 缺失标识符 非法的表达式开头 类型不兼容 非法的方法声明; ...