poj 1050(矩阵求和问题dp)
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 44765 | Accepted: 23700 |
Description
As an example, the maximal sub-rectangle of the array:
0 -2 -7 0
9 2 -6 2
-4 1 -4 1
-1 8 0 -2
is in the lower left corner:
9 2
-4 1
-1 8
and has a sum of 15.
Input
input consists of an N * N array of integers. The input begins with a
single positive integer N on a line by itself, indicating the size of
the square two-dimensional array. This is followed by N^2 integers
separated by whitespace (spaces and newlines). These are the N^2
integers of the array, presented in row-major order. That is, all
numbers in the first row, left to right, then all numbers in the second
row, left to right, etc. N may be as large as 100. The numbers in the
array will be in the range [-127,127].
Output
Sample Input
4
0 -2 -7 0 9 2 -6 2
-4 1 -4 1 -1 8 0 -2
Sample Output
15
Source
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define zero_(x,y) memset(x , y , sizeof(x))
#define zero(x) memset(x , 0 , sizeof(x))
#define MAX(x) memset(x , 0x3f ,sizeof(x))
using namespace std ;
#define N 505
typedef long long LL ;
LL dp[N],a[N][N],s[N][N];
int main(){
//freopen("in.txt","r",stdin);
int n;
scanf("%d",&n);
zero(dp);zero(a);zero(s);
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
scanf("%I64d",&a[i][j]);
}
}
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
s[j][i]=s[j-][i]+a[j][i]; }
} LL sum=,b=;
for(int i=;i<=n;i++){
for(int j=i+;j<=n;j++){
b=;
for(int k=;k<=n;k++){ if(b>)
b+=(s[j][k]-s[i][k]);
else
b=s[j][k]-s[i][k];
if(b>sum)
sum=b; }
}
}
printf("%I64d\n",sum);
return ;
}
poj 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 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- poj 1195:Mobile phones(二维线段树,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14391 Accepted: 6685 De ...
- POJ 1651:Multiplication Puzzle 矩阵相乘式DP
Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7118 Accepted: ...
- poj 1050 To the Max(最大子矩阵之和)
http://poj.org/problem?id=1050 我们已经知道求最大子段和的dp算法 参考here 也可参考编程之美有关最大子矩阵和部分. 然后将这个扩大到二维就是这道题.顺便说一下,有 ...
- poj 1185(状态压缩DP)
poj 1185(状态压缩DP) 题意:在一个N*M的矩阵中,‘H'表示不能放大炮,’P'表示可以放大炮,大炮能攻击到沿横向左右各两格,沿纵向上下各两格,现在要放尽可能多的大炮使得,大炮之间不能相互 ...
- poj 3254(状态压缩DP)
poj 3254(状态压缩DP) 题意:一个矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相 ...
- 【bzoj1778】[Usaco2010 Hol]Dotp 驱逐猪猡 矩阵乘法+概率dp+高斯消元
题目描述 奶牛们建立了一个随机化的臭气炸弹来驱逐猪猡.猪猡的文明包含1到N (2 <= N <= 300)一共N个猪城.这些城市由M (1 <= M <= 44,850)条由两 ...
- UVA 11149-Power of Matrix(等比矩阵求和)
给定一个矩阵A 要求A + A^2 + A^3 +…. A^k: 对于到n的等比矩阵求和 如果n是偶数: 如果n是奇数: #include<stdio.h> #include<s ...
随机推荐
- Centos下Mysql密码忘记解决办法
1.修改MySQL的登录设置: # vim /etc/my.cnf 在[mysqld]的段中加上一句:skip-grant-tables 例如: [mysqld] datadir=/var/lib/m ...
- CCD和CMOS的差别
单从感光器电子技术上来说,CCD比CMOS更先进,理论成像上有优势,但是最近几年CMOS却发展更好,使得很多高端数码单反采用CMOS传感器,下面来看看CCD和CMOS的技术知识: CCD和CMOS传感 ...
- UIPageControl---iOS-Apple苹果官方文档翻译
本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址 //转载请注明出处--本文永久链接:http://www.cnblogs.com/Ch ...
- java和C和C++关系
java和C以及C++ 直接关联,java继承了C的语法,java的对象模型是从C++改编而来的.java和C以及C++关系之所以重要,下面几个就是原因: ①如果一个程序员熟悉C以及C++语法,那么他 ...
- Python3 面向对象编程高级语法
1.静态方法: #!/usr/bin/env python # _*_ coding:utf-8 _*_ # Author:CarsonLi class Dog(object): def __init ...
- Django rest framework 权限操作(源码分析)
知识回顾http://www.cnblogs.com/ctztake/p/8419059.html 这一篇是基于上一篇写的,上一篇谢了认证的具体流程,看懂了上一篇这一篇才能看懂, 当用户访问是 首先执 ...
- 一种面向云服务的UCON多义务访问控制方法及系统
)设置每一云服务的义务项:建立每一云服务所包含的义务图:2)根据用户所请求的云服务查找该云服务的所有强制义务图和可选义务图,并提取该用户对该云服务的历史完成情况:3)对每一强制义务图,监控其每一义务项 ...
- 浅谈C语言中的强符号、弱符号、强引用和弱引用【转】
转自:http://www.jb51.net/article/56924.htm 首先我表示很悲剧,在看<程序员的自我修养--链接.装载与库>之前我竟不知道C有强符号.弱符号.强引用和弱引 ...
- v4l2驱动编写篇【转】
转自:http://blog.csdn.net/michaelcao1980/article/details/53008418 大部分所需的信息都在这里.作为一个驱动作者,当挖掘头文件的时候,你可能也 ...
- 【bzoj4486】【JSOI2015】串分割
老省选题了. 首先考虑怎么比较超长数字的大小? 参见UTR1的那道题 先比size,然后比较字典序即可. 接下来考虑下切割的问题. 因为要将字符串切割成k份,所以这个字符串只会存在n/k个本质不同的起 ...