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 ...
随机推荐
- HTML5智能表单
HTML5 智能表单 1.表单新增属性 ☀ autofocus 属性 <input type="text" autofocus/>设置 autofocus 属性,使文 ...
- Vue父子组件生命过程
加载渲染过程 父beforeCreate->父created->父beforeMount->子beforeCreate->子created->子beforeMount-& ...
- python的requests模块参数详解
import requests print(dir(requests)) # 1.方法 # ['ConnectTimeout', 'ConnectionError', 'DependencyWarni ...
- java中解析excel 批量插入数据库
Facade 层 实现类 (@Service("samePeriodModelImportFacade")) 1. 获取cells 的方法 public Cells getCel ...
- 20175234 2018-2019-2 《Java程序设计》第九周学习总结
目录 20175234 2018-2019-2 <Java程序设计>第九周学习总结 教材学习内容总结 教材学习中的问题和解决过程 代码托管 感想 学习进度条 参考资料 20175234 2 ...
- vue中html页面写入$t(‘’)怎么显示
1.在 main.js 中引入 vue-i18n (前提是要先引入 vue) 1 2 import VueI18n from'vue-i18n' Vue.use(VueI18n) 2.准备本地的翻译信 ...
- [DBNETLIB][ConnectionOpen(Invalid Instance())] 无效的连接 的解决办法
Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Data Source=192.168.1.28,1433 连接SQL serve ...
- [gazebo-1] process has died [pid 22855, exit code 255,
[gazebo-1] process has died [pid 22855, exit code 255, cmd /opt/ros/kinetic/lib/gazebo_ros/gzserver ...
- 信息在DNN马尔科夫链结构上的变化
一个经典的全连接神经网络,如下图所示,输入层可以看做T0,输出层可以看做$\hat{\mathrm{Y}}$=TL+1. 考虑每一层隐藏层T与X.Y的交互信息:I(X; Ti), I(Ti, Y),交 ...
- HDU4460
#include <iostream> #include <queue> #include <vector> #include <cstring> #i ...