poj 1050 最大子矩阵
a11 a12 a13 a14 a15
a21 a22 a23 a24 a25
a31 a32 a33 a34 a35
a41 a42 a43 a44 a45
a51 a52 a53 a54 a55
枚举矩阵每一列的区间,当成最长子串的dp方式就能过了
你把a21 a31 a41 看成一个元素,值是这三个元素的和,后面的列同理
https://www.cnblogs.com/GodA/p/5237061.html
这个人讲的非常好
#include<iostream>
#include <cstdio>
using namespace std;
const int maxn = ;
int arr[maxn][maxn];
int sum[maxn][maxn];
int main()
{
int n;
scanf("%d",&n);
for(int i = ; i <= n; ++i )
{
for(int j = ; j <= n; ++j)
{
scanf("%d",&arr[i][j]);
}
}
for(int i = ; i <= n; ++i)
{
for(int j = ; j <= n; ++j)
{
sum[i][j] = sum[i][j-] + arr[j][i];
}
}
/*for(int i = 1; i <= n; ++i)
{
for(int j = 1; j <= n; ++j)
{
printf("%d\n",sum[i][j]);
}
}*/
int maix = ;
for(int i = ; i <= n; ++i)
{
for(int j = i+; j <= n; ++j)
{
int b = ;
for(int k = ; k <= n; ++k )
{
if(b > )
{
b += sum[k][j] - sum[k][i];
}
else
{
b = sum[k][j] - sum[k][i];
}
if(b > maix)
maix = b;
}
}
}
printf("%d\n",maix);
}
poj 1050 最大子矩阵的更多相关文章
- poj 1050 To the Max(最大子矩阵之和)
http://poj.org/problem?id=1050 我们已经知道求最大子段和的dp算法 参考here 也可参考编程之美有关最大子矩阵和部分. 然后将这个扩大到二维就是这道题.顺便说一下,有 ...
- POJ 1050 To the Max 最大子矩阵和(二维的最大字段和)
传送门: http://poj.org/problem?id=1050 To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submi ...
- [ACM_动态规划] POJ 1050 To the Max ( 动态规划 二维 最大连续和 最大子矩阵)
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 ...
- poj 1050 To the Max_dp求最大子矩阵和
题意:求最大子矩阵和 利用dp[i]每次向下更新,构成竖起的单条矩阵,再按不小于零就加起来来更新,构成更大的矩阵 #include <iostream> #include<cstdi ...
- POJ 1050 To the Max (最大子矩阵和)
题目链接 题意:给定N*N的矩阵,求该矩阵中和最大的子矩阵的和. 题解:把二维转化成一维,算下就好了. #include <cstdio> #include <cstring> ...
- hdu 1081 & poj 1050 To The Max(最大和的子矩阵)
转载请注明出处:http://blog.csdn.net/u012860063 Description Given a two-dimensional array of positive and ne ...
- 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 最大连续子矩阵和
Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous s ...
随机推荐
- spring 自定参数解析器(HandlerMethodArgumentResolver)
https://blog.csdn.net/u010187242/article/details/73647670
- SourInsight4 配置视野内引用高亮
- 【docker 入门 - 01】- Docker 在 Centos7 上安装与测试
一.学习文档 官网网站: https://www.docker.com 中文网站:http://www.docker-cn.com 官方安装文档:https://docs.docker.com/ins ...
- Servlet第一篇(Tomcat)
Tomcat 什么是Tomcat Tomcat简单的说就是一个运行JAVA的网络服务器,底层是Socket的一个程序,它也是JSP和Serlvet的一个容器. 为什么我们需要用到Tomcat 提供能够 ...
- Floyd-Warshall算法计算有向图的传递闭包
Floyd-Warshall算法是用来求解所有结点对最短路径的知名算法,其还有一个重要的用途就是求解有向图的传递闭包,下面就让我来介绍算法导论中关于有向图闭包计算的有关记载吧. 有向图的传递闭包:我们 ...
- 通过decorators = [,] 的形式给类中的所有方法添加装饰器
给类添加装饰器有多种方法: 1.可以在类中的某个方法上边直接@添加,这个粒度细.无需详细介绍 2.也可以在类中通过 decorators=[, ]的形式添加,这样的话,类中的所有方法都会被一次性加上装 ...
- 关于项目里server清楚缓存的代码
Venk proc存在很多问题,不能应对高并发的情况,所以提供了这个 方法来清理cache, 但是前提是需要有prod的权限: 要想验证是否通过URL清楚了缓存,就要 removeCache url执 ...
- UNIX 系统下退出 git commit 编辑器
如果是 Emacs 编辑器,输入 Ctrl X + Ctrl S(保存),再输入Ctrl X + Ctrl C(退出) 如果是VIM编辑器,输入 ESC + :wq UNIX 系统默认打开的是 Ema ...
- 13. Redis监控运维云平台CacheCloud
13. Redis监控运维云平台CacheCloud13.1 CacheCloud是什么13.1.1 现有问题13.1.2 CacheCloud基本功能13.2 快速部署13.2.1 CacheClo ...
- gooflow学习笔记
前端jqury脚本实现流程设计,兼容目前主流浏览器 gooflow 默认属性节点只有:id,name,top,left,width,height,type (各个版本不同,属性节点有所增加),但是这些 ...