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 ...
随机推荐
- 全面认识JVM技术
本文向大家描述一下JVM的概念,JVM(Java虚拟机)是可运行Java代码的假想计算机.只要根据JVM规格描述将解释器移植到特定的计算机上,就能保证经过编译的任何Java代码能够在该系统上运行. J ...
- UML标准图(转载)
在前面的章节中,我们已经讨论过的构建和其他必要的UML元素.现在,我们需要明白的地方使用这些元素. 元素都可以以不同的方式,使一个被称为图的完整的UML图片,如:组件.所以这是非常重要的,要了解不同的 ...
- Unity3D研究院之LZMA压缩文件与解压文件
原地址:http://www.xuanyusong.com/archives/3095 前两天有朋友告诉我Unity的Assetbundle是LZMA压缩的,刚好今天有时间那么就研究研究LZMA.它是 ...
- AssetBundle机制相关资料收集
原地址:http://www.cnblogs.com/realtimepixels/p/3652075.html AssetBundle机制相关资料收集 最近网友通过网站搜索Unity3D在手机及其他 ...
- jboss 占用cpu 100%
通过Java thread dump分析找到耗费CPU最高的源代码 分类: 9. Java2010-04-11 23:06 9272人阅读 评论(4) 收藏 举报 threadjavaeclipse插 ...
- Java异步消息平台
l JAVA平台异步消息模块 JAVA平台异步消息模块,是一个针对RabbitMQ的消息发送及处理封装,包含消息的配置.发送.接收.失败重试.日志记录等,总共分为4个部分: 1)RabbitMQ访问 ...
- js中的call与apply
看js权威指南里面关于call与apply方法的说明:我们可以将call()与apply()看作是某个对象的方法,通过调用方法的形式来间接调用函数.这样的解释未免使人糊涂啊.下面说一下自己的见解:其实 ...
- C# 任意类型数据转JSON格式
/// <summary> /// List转成json /// </summary> /// <typeparam name="T">< ...
- 多页面打印--web print
背景:项目中要求做在一个页面中通过选择网址来打印多个页面的内容的功能 原理:通过iframe把各网址的页面内容加载进来,通过iframe.contentWindow拿到iframe的window对象, ...
- Linux中查看进程的多线程
在SMP系统中,我们的应用程序经常使用多线程的技术,那么在Linux中如何查看某个进程的多个线程呢? 本文介绍3种命令来查看Linux系统中的线程(LWP)的情况: 在我的系统中,用qemu-syst ...