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 ...
随机推荐
- Error merging: refusing to merge unrelated histories
解决方案: git pull git pull origin master git pull origin master --allow-unrelated-histories idea提交git提交 ...
- py_innodb_page_info
python py_innodb_page_info.py -v /usr/local/var/mysql/ibdata1 mylib.py #encoding=utf-8 import os imp ...
- QT Designer基础——登录界面设计基础版
认识QT Designer提供的可选控件:以下八个大类 Layouts:布局相关 Spacers:留空 Buttons:可点击的按钮类 Item Views和 Item Widgets:高级控件,例如 ...
- python note 09 初识函数
1.函数 def my_len(): #自定义函数(相当于len) i = 0 for k in s: i += 1 print(i) print(my_len()) #输出None,因为没有返回值 ...
- project5 大数据
[概念] build和run不是一样的,要看输出,不要误解. [方法论] 先要搞懂每个方法的使用,不能乱写.文件名不要写成字符串内容. 又忘记用lab code了,该死. programcreek是个 ...
- pythone函数基础(15)接口开发初识
导入需要的第三方模块 import flaskimport toolsimport json,redisimport random server = flask.Flask(__name__)#新建一 ...
- xmltodict 模块
pip install xmltodict xmltodict.parse() 方法可以将xml数据转为python中的dict字典数据 xmltodict.unparse() 将字典转换为xml数据 ...
- hanjiaqi
2017*1501:我是韩佳琦:我的爱好是睡觉: 我的码云个人主页是:https://gitee.com/projects/new 我的第一个项目地址是:https://gitee.com/hanji ...
- 安装swoole
php需要安装swoole扩展 swoole4.3.2 cd /usr/local/src/ wget https://pecl.php.net/get/swoole-4.3.2.tgz tar -z ...
- core里使用log4net
1. nuget 里安装 log4net 2. startup.cs里配置读取配置文件 public static ILoggerRepository repository { get; set; } ...