poj 1050 To the Max (简单dp)
题目链接:http://poj.org/problem?id=1050
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std; const int maxn = ;
const int INF = 0x3f3f3f; int dp[maxn];
int sum[maxn][maxn];
int ans; int main()
{
//freopen("E:\\acm\\input.txt","r",stdin);
int N;
cin>>N;
for(int i=;i<=N;i++) sum[][i] = sum[i][] = ;
for(int i=;i<=N;i++)
for(int j=;j<=N;j++){
int a;
scanf("%d",&a);
sum[i][j] = sum[i-][j] + a;
}
ans = -INF;
for(int i=;i<=N;i++)
for(int j=i;j<=N;j++){
memset(dp,,sizeof(dp));
for(int k=;k<=N;k++){
dp[k] = max(,dp[k-]) + sum[j][k] - sum[i][k];
ans = max(dp[k],ans);
}
}
printf("%d\n",ans);
}
//自己的做时候,一直想怎样写dp并表示出状态转移方程,但是就是怎么也想不出来,觉得不好表示。没办法看了别人的想法,马上反应过来。头脑僵化了啊!!!
poj 1050 To the Max (简单dp)的更多相关文章
- poj - 1050 - To the Max(dp)
题意:一个N * N的矩阵,求子矩阵的最大和(N <= 100, -127 <= 矩阵元素 <= 127). 题目链接:http://poj.org/problem?id=1050 ...
- poj 1050 To the Max(线性dp)
题目链接:http://poj.org/problem?id=1050 思路分析: 该题目为经典的最大子矩阵和问题,属于线性dp问题:最大子矩阵为最大连续子段和的推广情况,最大连续子段和为一维问题,而 ...
- POJ 1050 To the Max 枚举+dp
大致题意: 求最大子矩阵和 分析: 一开始想复杂了,推出了一个状态方程:d[i][j]=max(d[i][j-1]+-,d[i-1][j]+-).写着写着发现上式省略的部分记录起来很麻烦. 后来发现n ...
- [poj]1050 To the Max dp
Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...
- 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 Description Given a two-dimensional array of positive and negative integers, a sub-rect ...
- poj 1050 To the Max(最大子矩阵之和,基础DP题)
To the Max Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 38573Accepted: 20350 Descriptio ...
- POJ 1050 To the Max 暴力,基础知识 难度:0
http://poj.org/problem?id=1050 设sum[i][j]为从(1,1)到(i,j)的矩形中所有数字之和 首先处理出sum[i][j],此时左上角为(x1,y1),右下角为(x ...
随机推荐
- IOS pop使用代理传值
假如oneViewController页面push到OtherViewController页面,然后你想从OtherViewController页面pop到oneViewController页面的时候 ...
- Objective-C发展历史
Objective-C发展历史 苹果图标由来: 被咬了一口苹果的LOGO是为了纪念计算机科学的创始人阿兰· 麦席森· 图灵.当年图灵由于身为同性恋者,被强行 "治疗",在被迫注射大 ...
- MVVM模式应用 之在ViewModel中使用NavigationService
在ViewModel.cs页面中是不能使用NavigationService,那该怎么实现跳转呢? 其实在ViewModel中实现页面的跳转也很简单,下面的代码: using Microsoft.Ph ...
- demo_03HTML5中的动画效果
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 【C语言】中的stdbool.h头文件
C语言中的stdbool.h头文件 一.相关基础知识 二.具体内容 Win7下安装的VS2015中的stdbool.h的位置为: F:\Program Files (x86)\Microsoft Vi ...
- Sharepoint 问题集锦 - 外部列表(external list) - 读取当前用户上下文或用户名作为筛选参数
在创建外部列表过程中,往往需要添加筛选参数,而较多开发用户,会关心如何在外部列表中,只显示当前用户相关的行.本例子中,我们以任务数据表来做例子,看看如何实现这个需求. 1)数据表tbl_task: t ...
- jq总结1
选择器 /** * 多目标选择器 * 可以选择多个元素或者表达式, * 包装成 jQuery 对象的集合 * 例子:$("div,span") */ $("table t ...
- matlab的二维卷积操作
MATLAB的conv2函数实现步骤(conv2(A,B)): 其中,矩阵A和B的尺寸分别为ma*na即mb*nb ① 对矩阵A补零,第一行之前和最后一行之后都补mb-1行,第一列之前和最后一列之后都 ...
- apache pdfbox
转 http://www.blogjava.net/sxyx2008/archive/2010/07/23/326890.html 轻松使用apache pdfbox将pdf文件生成图 近期在项目中使 ...
- bzoj 2049: [Sdoi2008]Cave 洞穴勘测 动态树
2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 3119 Solved: 1399[Submit] ...