POJ 1050 To the Max (最大子矩阵和)
题意:给定N*N的矩阵,求该矩阵中和最大的子矩阵的和。
题解:把二维转化成一维,算下就好了。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll N=1e3+;
ll ans=-,tmp,data[N][N],a[N];
int ansi1=,ansj1=,ansi2=,ansj2=,tmp1=,tmp2=,n,m;
int main()
{
while(scanf("%d",&n)!=EOF){
m=n; ans=-;
memset(data,,sizeof(data));
for(int i=;i<=n;i++)
for(int j=;j<=m;j++){
scanf("%lld",&data[i][j]);
data[i][j]+=data[i-][j];
}
for(int i=;i<=n;i++)
for(int k=;k<i;k++)
{
memset(a,,sizeof(a));
tmp=;
for(int j=;j<=m;j++){
a[j]=data[i][j]-data[k][j];
tmp+=a[j];
tmp=max(tmp,0LL);
ans=max(ans,tmp);
}
}
printf("%lld\n",ans);
}
return ;
}
POJ 1050 To the Max (最大子矩阵和)的更多相关文章
- 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 Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 38573Accepted: 20350 Descriptio ...
- poj 1050 To the Max 最大子矩阵和 经典dp
To the Max Description Given a two-dimensional array of positive and negative integers, a sub-rect ...
- [ACM_动态规划] POJ 1050 To the Max ( 动态规划 二维 最大连续和 最大子矩阵)
Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...
- 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)
题意:一个N * N的矩阵,求子矩阵的最大和(N <= 100, -127 <= 矩阵元素 <= 127). 题目链接:http://poj.org/problem?id=1050 ...
- 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 ...
- POJ 1050 To the Max -- 动态规划
题目地址:http://poj.org/problem?id=1050 Description Given a two-dimensional array of positive and negati ...
随机推荐
- 复利计算程序单元测试(C语言)
对我们和复利计算程序,写单元测试. 有哪些场景? 期待的返回值 写测试程序. 运行测试. 我的复利计算程序是用C语言写的,不懂使用C语言的测试工具,所以用C语言的运行结果来反映测试结果. 测试模块(场 ...
- 【转】mysql force Index 强制索引
其他强制操作,优先操作如下: mysql常用的hint 对于经常使用oracle的朋友可能知道,oracle的hint功能种类很多,对于优化sql语句提供了很多方法.同样,在mysql里,也有类似的h ...
- sublime py不能输入中文
设置环境变量PYTHONIOENCODING=UTF-8,重启sublime即可 转载请注明博客出处:http://www.cnblogs.com/cjh-notes/
- 第116天: Ajax运用artTemplate实现菜谱
Ajax运用artTemplate实现菜谱 一.获取接口数据 1.聚合数据API https://www.juhe.cn,在这上面找到菜谱大全数据接口文档 具体使用是这样的: key后面的数据是 ...
- 洛谷 P1560 蜗牛的旅行
明显这是一道搜索题,其他题解写的有点复杂,我有更简便的写法 既然题目说走到不能再走,那我们就干脆一点,一条路走到黑,不到南墙不回头,一下把要走的路都走完,不但效率高,也好写,关键是大大节省了系统栈 一 ...
- 洛谷P4608 [FJOI2016]所有公共子序列问题 【序列自动机 + dp + 高精】
题目链接 洛谷P4608 题解 建个序列自动机后 第一问暴搜 第二问dp + 高精 设\(f[i][j]\)为两个序列自动机分别走到\(i\)和\(j\)节点的方案数,答案就是\(f[0][0]\) ...
- c语言中,指针加1的情况.指针变量详细介绍
指针是一个特殊的变量,它里面存储的数值被解释成为内存里的一个地址. 要搞清一个指针需要搞清指针的四方面的内容: 指针的类型, 指针所指向的 类型, 指针的值或者叫指针所指向的内存区, 还有指针本身所占 ...
- open_basedir restriction in effect的错误及其解决办法
问题是出现在了PHP.INI上面了 原因是php.ini里设置了 opendir=/var/web/w0895/:/tmp:/usr/lib/php 解答: 其实open_basedir ...
- 解题:CTSC 2017 吉夫特
题面 首先有个结论:$C_n^m$为奇数当且仅当$m$是$n$的一个子集 于是从后往前推,记录每个数出现的位置,然后对每个位置枚举子集统计在它后面的贡献即可 #include<cstdio> ...
- 【神仙题】【CF28D】 Don't fear, DravDe is kind
传送门 Description 一个有N辆卡车的车队从城市Z驶向城市3,来到了一条叫做"恐惧隧道"的隧道.在卡车司机中,有传言说怪物DravDe在那条隧道里搜寻司机.有些司机害怕先 ...