POJ 1050 To the Max 枚举+dp
大致题意:
求最大子矩阵和
分析:
一开始想复杂了,推出了一个状态方程:d[i][j]=max(d[i][j-1]+…,d[i-1][j]+…)。写着写着发现上式省略的部分记录起来很麻烦。
后来发现n最大100,干脆直接枚举行,先枚举所有行的情况,然后将矩阵压缩为数列,最后用最大子段和求解。写着写着感觉就会超时,毕竟出现了四层循环嵌套。结果过了,说明测试数据有点水。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std; const int maxn=100+5;
const int INF=1e7;
int a[maxn][maxn];
int b[maxn];
int ans; int main()
{
int n;
scanf("%d",&n);
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
scanf("%d",&a[i][j]);
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
{
memset(b,0,sizeof(b));
for(int k=0;k<n;k++)
for(int m=i;m<=j;m++)
b[k]+=a[m][k];
int maxs=b[0];
for(int k=1;k<n;k++)
{
if(b[k-1]>0) b[k]+=b[k-1];
maxs=max(maxs,b[k]);
}
ans=max(maxs,ans);
}
printf("%d\n",ans);
return 0;
}
POJ 1050 To the Max 枚举+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)
题目链接: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
Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...
- POJ 1050 To the Max 最大子矩阵和(二维的最大字段和)
传送门: http://poj.org/problem?id=1050 To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submi ...
- poj 1050 To the Max(最大子矩阵之和)
http://poj.org/problem?id=1050 我们已经知道求最大子段和的dp算法 参考here 也可参考编程之美有关最大子矩阵和部分. 然后将这个扩大到二维就是这道题.顺便说一下,有 ...
- 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(最大子矩阵之和,基础DP题)
To the Max Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 38573Accepted: 20350 Descriptio ...
- POJ 1050 To the Max 暴力,基础知识 难度:0
http://poj.org/problem?id=1050 设sum[i][j]为从(1,1)到(i,j)的矩形中所有数字之和 首先处理出sum[i][j],此时左上角为(x1,y1),右下角为(x ...
随机推荐
- linux操作系统优化系列-RAID不同阵列模式的选择
背景 笔者所在的某通信运营商某大数据项目由于应用面临瓶颈需要扩充服务器设备,当初上这个项目的时候,服务器上线前的工作(配置raid,安装操作系统,Infiniband网络调试,系统漏洞安全加固)都是我 ...
- python上下文管理协议,即with的详细使用
一.with obj as f: #代码块... 二.执行流程: 1.with obj --->触发obj.__enter__(),需要在obj里写__enter__(self),在它里边写返回 ...
- rsync同步遇到的报错和解决办法
rsync同步遇到的报错和解决办法 科技小能手 2017-11-12 18:27:00 浏览1125 配置 code 同步 open stream file read 在同步的客户端操作: [ ...
- ft2000安装tigervnc
apt update apt install tigervnc*vncserver :88 history >>history
- DOCKER学习_018:Docker-Compose文件简介
Docker-Compose文件 通过之前的示例,其实我们可以看到,所有服务的管理,都是依靠docker-compose.yml文件来实现的.那么我们接下来就详细说一说docker-compose.y ...
- 技术干货 | 轻松两步完成向 mPaaS 小程序传递启动参数
前言 在部分场景下,需要向小程序的默认接收页(pages/index/index)传递参数. 本文将以传递 name 和 pwd 参数为例,分别介绍此场景在 Android 小程序和 iOS 小程序中 ...
- 20192113 2020-2021-2 《Python程序设计》实验二报告
20192113 2020-2021-2 <Python程序设计>实验二报告 课程:<Python程序设计> 班级: 1921 姓名: 衣丽莎 学号:20192113 实验教师 ...
- SpringCloud(八)Sleuth 分布式请求链路跟踪
SpringCloud Sleuth 分布式请求链路跟踪 概述 为什么会出现这个技术?需要解决哪些问题? 在微服务框架中,一个由客户端发起的请求在后端系统中会经过多个不同的的服务节点调用来协同产生最后 ...
- MyBatis-编写自定义分页插件
一.基础知识 本文测试和源码分析参考版本: Mybatis-version:3.5.5 本文相关测试源代码:https://github.com/wuya11/mybatis_demo 1.1 参考方 ...
- Ascend Pytorch算子功能验证
Ascend Pytorch算子功能验证 编写测试用例 以add算子为例,测试脚本文件命名为:add_testcase.py.以下示例仅为一个简单的用例实现,具体算子的实现,需要根据算子定义进行完整的 ...