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 ...
随机推荐
- Mac Zip命令
mac终端命令 zip -[parameter] [yourName].zip someFileOrDiectory -q 表示不显示压缩进度状态 -r 表示子目录子文件全部压缩为zip //这部比较 ...
- CALayer 认识
一篇很好的讲述calayer的博客 http://www.cnblogs.com/kenshincui/p/3972100.html
- iOS开发的技能树
1.UI2.多线程 3.网络 4.多媒体 5.存储 6.分布式 7.支付,第三方 8.地图,动画,二维码,打包 9.特效10.apple watch/ apple tv 11.swift 12.web ...
- mysql 链接数据库
一.MySQL 连接本地数据库,用户名为“root”,密码“root”(注意:“-p”和“root” 之间不能有空格) C:\>mysql -h localhost -u root -proot ...
- JAVA_HOME 的设置
1. 永久修改,对所有用户有效(不建议这么使用,对Oracle 等用户都有影响) # vi /etc/profile export JAVA_HOME=/usr/local/jdk1.8.0_20/e ...
- mouseover和mouseout事件在鼠标经过子元素时也会触发
JavaScript的mouseover和mouseout事件,在绑定元素内部有子元素的情况下, 经过绑定元素时会多次触发mouseover和mouseout事件. jQuery解决办法: jquer ...
- sql 建立数据库,表格,索引,主键
---- 数据库: `message_db`-- -- --------------------------------------------------------create database ...
- PinchEvent QML Type
PinchEvent类型在QtQuick 1.1中被添加进来.center, startCenter, previousCenter属性保存了两个触摸点之间的中心位置.scale and previo ...
- ubuntu下openGL的配置方法
This is a simple tutorial to show a new linux user (such as myself) how to setup freeglut and OpenGl ...
- 上网必备AdBlock,远离广告!
浏览器广告拦截插件,绝对上网必备... 从此告别讨厌的百度边栏广告!!! https://getadblock.com/ https://adblockplus.org/zh_CN/