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 ...
随机推荐
- js获取,设置FCKeditor内容
// 获取编辑器中HTML内容 function getEditorHTMLContents(EditorName) { var oEditor = FCKeditorAPI.GetInsta ...
- 服务接口API限流 Rate Limit 续
一.前言 上一篇文章中粗浅的介绍使用Redis和基于令牌桶算法进行对服务接口API限流,本文介绍另一种算法---漏桶算法的应用.Nginx想必大家都有所了解是一个高性能的 HTTP 和反向代理服务器, ...
- SPOJ375 Query on a tree(LCT边权)
之前做了两道点权的LCT,这次做一下边权的LCT.上网找了一下资料,发现对于边权的LCT有这么两种处理方法,一种是每条边建一个点,于是边权就转成点权了.另外一种则是每个边权对应到点权上,也就是每个点对 ...
- LINGO使用教程(一)
LINGO是用来求解线性和非线性优化问题的简易工具.LINGO内置了一种建立最优化模型的语言,可以简便地表达大规模问题,利用LINGO高效的求解器可快速求解并分析结果. 1.LINGO快速入门 当你在 ...
- java基础知识回顾之javaIO类---FileInputStream和FileOutputStream字节流复制图片
package com.lp.ecjtu; import java.io.FileInputStream; import java.io.FileNotFoundException; import j ...
- DOS永久设置系统环境变量-WMIC
wmic Windows Management Instrumentation Command-line(Windows管理规范命令行) WMIC扩展WMI(Windows Management In ...
- .bat后台运行
可以编辑一个vbs脚本,在其中以隐藏窗口运行批处理程序. ------------------------------------------------------------ Set ws = C ...
- ExtJs之Ext.util.CSS
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- HDU5597/BestCoder Round #66 (div.2) GTW likes function 打表欧拉函数
GTW likes function Memory Limit: 131072/131072 K (Java/Others) 问题描述 现在给出下列两个定义: f(x)=f_{0}(x)=\ ...
- 【poj2778-DNA Sequence】AC自动机+矩阵乘法
题意: (只含AGCT)给定m个病毒串,让你构造一个长度为n的字符串(也只含有AGCT),问有多少种方案.n很大:1<=n<=2000000000 题解: 用病毒串建立AC自动机(num个 ...