poj 1050(DP)
最大子矩阵和。类似于子序列最大和。
// File Name: 1050.cpp
// Author: Missa_Chen
// Created Time: 2013年06月22日 星期六 17时06分39秒 #include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <cstdlib> using namespace std; #define LL long long
const int inf = 0x3f3f3f3f;
const int maxn = ;
int n;
int sum[maxn][maxn];
int main()
{
while (~scanf("%d",&n))
{
for (int i = ; i <= n; ++i)
for (int j = ; j <= n; ++j)
scanf("%d", &sum[i][j]);
for (int i = ; i <= n; ++i)
sum[i][] = ;
for (int i = ; i <= n; ++i)
for (int j = ; j <= n; ++j)
sum[i][j] += sum[i][j - ];
int ans = -inf;
for (int i = ; i <= n; ++i)
for (int j = i; j <= n; ++j)
{
int tmp = -inf;
for (int k = ; k <= n; ++k)
{
if (tmp >= )
tmp += (sum[k][j] - sum[k][i - ]);
else
tmp = sum[k][j] - sum[k][i - ];
ans = max(ans, tmp);
}
}
printf("%d\n", ans);
}
return ;
}
poj 1050(DP)的更多相关文章
- poj 1050 To the Max(最大子矩阵之和)
http://poj.org/problem?id=1050 我们已经知道求最大子段和的dp算法 参考here 也可参考编程之美有关最大子矩阵和部分. 然后将这个扩大到二维就是这道题.顺便说一下,有 ...
- poj 1050 To the Max (简单dp)
题目链接:http://poj.org/problem?id=1050 #include<cstdio> #include<cstring> #include<iostr ...
- poj 1050 To the Max(线性dp)
题目链接:http://poj.org/problem?id=1050 思路分析: 该题目为经典的最大子矩阵和问题,属于线性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
To the Max Description Given a two-dimensional array of positive and negative integers, a sub-rect ...
- poj 1050(矩阵求和问题dp)
To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44765 Accepted: 23700 Desc ...
- [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(最大子矩阵之和,基础DP题)
To the Max Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 38573Accepted: 20350 Descriptio ...
- 简单DP+暴力 POJ 1050
To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 45915 Accepted: 24282 Desc ...
随机推荐
- Maven在项目中的应用
http://192.168.0.253:8081/nexus/#view-repositories;thirdparty~uploadPanel 使用局域网搭建的环境,输入用户名和密码登录,上传ja ...
- Python日志输出——logging模块
Python日志输出——logging模块 标签: loggingpythonimportmodulelog4j 2012-03-06 00:18 31605人阅读 评论(8) 收藏 举报 分类: P ...
- 整数划分 Integer Partition(一)
话说今天百度面试,可能是由于我表现的不太好,面试官显得有点不耐烦,说话的语气也很具有嘲讽的意思,搞得我有点不爽.Whatever,面试中有问到整数划分问题,回答这个问题过程中被面试官搞的不胜其烦,最后 ...
- Android内存泄漏问题(一)
前言 不少人认为JAVA程序,因为有垃圾回收机制,应该没有内存泄露. 其实如果我们一个程序中,已经不再使用某个对象,但是因为仍然有引用指向它,垃圾回收器就无法回收它,当然该对象占用的内存就无法被使用, ...
- C# 工厂
/// <summary> /// 创造实例 /// </summary> /// <typeparam name="T">类型</typ ...
- hdu 1531(差分约束)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1531 差分约束的题之前也碰到过,刚好最近正在进行图论专题的训练,就拿来做一做. ①:对于差分不等式,a ...
- js小技巧(二)
//移动的图层,拖动 1.<span style='position:absolute;width:200;height:200;background:red' onmousedown=Mous ...
- 深入理解Windows X64调试
随着64位操作系统的普及,都开始大力进军x64,X64下的调试机制也发生了改变,与x86相比,添加了许多自己的新特性,之前学习了Windows x64的调试机制,这里本着“拿来主义”的原则与大家分享. ...
- jmeter if 控制器
判断变量值是不是为空(有没有被赋值): "${jd_aid}"!="\${jd_aid}"
- hadoop 2.0 native
1.安装protobuf,参照http://wiki.apache.org/hadoop/HowToContribute 安装java模块 在java目录mvn install 2.配置protobu ...