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 ...
随机推荐
- 二模 (2) day2
第一题: 题目描述: 在一个长方形框子里,最多有 N(0≤N≤6)个相异的点.在其中任何-个点上放一个很小的油滴,那么这个油滴会一直扩展,直到接触到其他油滴或者框子的边界.必须等一个油滴扩展完毕才能放 ...
- 其他窗体赋值给comboBox实现值的回显,并使赋的值处于选中状态(根据text获取selectedindex)
Form1 发货单位的这个下拉框comboBox1已经绑定数据库test表的name字段,里面有很多单位名称 比如有:甲公司.乙公司... 1.Form1的comboBox1首先绑定数据库的数据表te ...
- RHEL 6.3安装(超级详细图解教程)[转载]
附:RHEL6.3下载地址 32位:http://rhel.ieesee.net/uingei/rhel-server-6.3-i386-dvd.iso 64位:http://rhel.iee ...
- PhpStorm WebMatrix xDebug 配置开发环境
1.首先下载WebMatrix安装程序,下载地址 http://www.microsoft.com/web/webmatrix/ 安装步骤 参考:http://www.jb51.net/softjc ...
- 使用rosed编辑ROS文件
1.1使用rosed. rosed是rosbash套件的一部分.它可以使你通过package的名字直接编辑一个package中的文件而不用输入package的整个路径. 用法: $ rosed [pa ...
- encodeURI
encodeURI("http://www.cnblogs.com/season-huang/some other thing"); //整个URL进行编码"http:/ ...
- 【STL】-迭代器的用法
初始化: list<char>::iterator pos; 算法: 1. 遍历 for(pos = col1.begin(); pos != col1.end(); ++pos){... ...
- opencv+ffmpeg实现avi视频的播放
配了一天,终于成功的在ubuntu上安装了ffmpeg,实现了opencv对avi文件的读取. 在CvCapture* pCapture=cvCaptureFromAVI("video.av ...
- K2十年:专注BPM
<聚·谋·变——K2中国用户大会> 导演:K2中国 主演:K2用户 时长:420分钟 票价:免费 上映日期:2015年7月17日 查看完整视频请关注K2官方微信账号
- for循环和while循环的区别
public class Xunhuanqubie { public static void main(String[] args){ int i = 0; while(i<8){ System ...