ZOJ 1074 To the Max
题目大意:这是一道好题。在《算法导论》这本书里面,有一节是介绍如何求最大子序列的。这道题有点类似,区别是从数组变成了矩阵,求最大子矩阵。
解法:完全没有算法功底的人当然不知道最大子序列这么经典的东西。所以先请教Google。我是参考了这篇文章的,tengpi.blog.163.com/blog/static/22788264200772561412895/。大意就是另开辟一个同样大小的矩阵,每个元素存放自左侧第一列到该元素的和。然后在纵向上用最大子序列的类似方法计算。
参考代码:
/* tengpi.blog.163.com/blog/static/22788264200772561412895/ */
#include<iostream>
using namespace std;
int main(){
int N,i,j,k,btemp,max=-12700;
int A[100][101],B[100][101];
while(cin>>N){
for(i=0;i<N;i++){
B[i][0]=0;
for(j=1;j<=N;j++){
cin>>A[i][j];
}
}
for(i=0;i<N;i++){
btemp=0;
for(j=1;j<=N;j++){
btemp+=A[i][j];
B[i][j]=btemp;
}
}
for(i=0;i<N;i++){
for(j=i+1;j<=N;j++){
btemp=0;
for(k=0;k<N;k++){
btemp+=B[k][j]-B[k][i];
if(btemp>max)max=btemp;
if(btemp<0)btemp=0;
}
}
}
cout<<max<<endl;
}
return 0;
}
ZOJ 1074 To the Max的更多相关文章
- ZOJ 1074 To the Max(DP 最大子矩阵和)
To the Max Time Limit: 2 Seconds Memory Limit: 65536 KB Problem Given a two-dimensional array o ...
- HDOJ 1081(ZOJ 1074) To The Max(动态规划)
Problem Description Given a two-dimensional array of positive and negative integers, a sub-rectangle ...
- ZOJ 1074 最大子矩阵和
Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- 1074, "Column length too big for column 'err_solution' (max = 21845); use BLOB or TEXT instead"
一个注意点,就是sqlalchemy 使用create_all()建表的时候,要在 create_all()所在页面import那些表的model sqlalchemy.exc.Operational ...
- ZOJ 3201 Tree of Tree
树形DP.... Tree of Tree Time Limit: 1 Second Memory Limit: 32768 KB You're given a tree with weig ...
- hdu 1024 Max Sum Plus Plus
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- zoj 3795 Grouping tarjan缩点 + DGA上的最长路
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Status Practic ...
随机推荐
- bzoj 2257: [Jsoi2009]瓶子和燃料
#include<cstdio> #include<iostream> #include<algorithm> #include<cmath> usin ...
- c++普通高精除单精
//没有在网上测试 //手测几组无误 //如有错误,还望指出,不胜感激. #include<cstdio>#include<cstring>int a1[600],a2,a4[ ...
- POJ 3094 Quicksum 难度:0
http://poj.org/problem?id=3094 #include<iostream> #include <string> using namespace std; ...
- C++-高效的swap
原始版本: template<typename T> void swap(T& a, T& b) { T tmp(a); a = b; b = tmp; } 此版本不重视效 ...
- 基于MVC模式的应用框架之struts
1.struts开发步骤 引入struts的jar包: 在web.xml中引入struts的核心功能,配置struts核心过滤器:(如果项目中用到了其他过滤器,要放在struts过滤器之前,否则会失效 ...
- 对项目的测试--Resharper
初学 这里做个记录. 1:安装后,Resharper会用他自己的英文智能提示,替换掉 vs2010的智能提示,所以我们要换回到vs2010的智能提示 2:快捷键.是使用vs2010的快捷键还是使用 R ...
- Spring AOP中pointcut expression表达式解析 及匹配多个条件
Spring中事务控制相关配置: <bean id="txManager" class="org.springframework.jdbc.datasource.D ...
- JS获取上传文件的名称、格式、大小
<input id="File1" type="file" onchange="checkFile(this)" /> 方式一) ...
- GoldenGate 之 Bounded Recovery说明
首先,我们来看两个OGG同步中可能的问题: l oracle在线日志包含已提交的和未提交的事务,但OGG只会将已提交的事务写入到队列文件.因此,针对未提交的事务,特别是未提交的长事务,OGG会怎样处理 ...
- sql学习资料
http://blog.sina.com.cn/s/articlelist_1594135432_9_1.html