大致题意:

求最大子矩阵和

分析:

一开始想复杂了,推出了一个状态方程:d[i][j]=max(d[i][j-1]+…,d[i-1][j]+…)。写着写着发现上式省略的部分记录起来很麻烦。

后来发现n最大100,干脆直接枚举行,先枚举所有行的情况,然后将矩阵压缩为数列,最后用最大子段和求解。写着写着感觉就会超时,毕竟出现了四层循环嵌套。结果过了,说明测试数据有点水。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <cstring>
  6. using namespace std;
  7.  
  8. const int maxn=100+5;
  9. const int INF=1e7;
  10. int a[maxn][maxn];
  11. int b[maxn];
  12. int ans;
  13.  
  14. int main()
  15. {
  16. int n;
  17. scanf("%d",&n);
  18. for(int i=0; i<n; i++)
  19. for(int j=0; j<n; j++)
  20. scanf("%d",&a[i][j]);
  21. for(int i=0; i<n; i++)
  22. for(int j=0; j<n; j++)
  23. {
  24. memset(b,0,sizeof(b));
  25. for(int k=0;k<n;k++)
  26. for(int m=i;m<=j;m++)
  27. b[k]+=a[m][k];
  28. int maxs=b[0];
  29. for(int k=1;k<n;k++)
  30. {
  31. if(b[k-1]>0) b[k]+=b[k-1];
  32. maxs=max(maxs,b[k]);
  33. }
  34. ans=max(maxs,ans);
  35. }
  36. printf("%d\n",ans);
  37. return 0;
  38. }

POJ 1050 To the Max 枚举+dp的更多相关文章

  1. poj - 1050 - To the Max(dp)

    题意:一个N * N的矩阵,求子矩阵的最大和(N <= 100, -127 <= 矩阵元素 <= 127). 题目链接:http://poj.org/problem?id=1050 ...

  2. poj 1050 To the Max (简单dp)

    题目链接:http://poj.org/problem?id=1050 #include<cstdio> #include<cstring> #include<iostr ...

  3. poj 1050 To the Max(线性dp)

    题目链接:http://poj.org/problem?id=1050 思路分析: 该题目为经典的最大子矩阵和问题,属于线性dp问题:最大子矩阵为最大连续子段和的推广情况,最大连续子段和为一维问题,而 ...

  4. [poj]1050 To the Max dp

    Description Given a two-dimensional array of positive and negative integers, a sub-rectangle is any ...

  5. POJ 1050 To the Max 最大子矩阵和(二维的最大字段和)

    传送门: http://poj.org/problem?id=1050 To the Max Time Limit: 1000MS   Memory Limit: 10000K Total Submi ...

  6. poj 1050 To the Max(最大子矩阵之和)

    http://poj.org/problem?id=1050 我们已经知道求最大子段和的dp算法 参考here  也可参考编程之美有关最大子矩阵和部分. 然后将这个扩大到二维就是这道题.顺便说一下,有 ...

  7. poj 1050 To the Max 最大子矩阵和 经典dp

    To the Max   Description Given a two-dimensional array of positive and negative integers, a sub-rect ...

  8. poj 1050 To the Max(最大子矩阵之和,基础DP题)

    To the Max Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 38573Accepted: 20350 Descriptio ...

  9. 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 ...

随机推荐

  1. 自己封装的mysql应用类示例

    from pymysql import *class my_mysql_mud(object): def __init__(self,host,port,db,user,passwd,charset= ...

  2. unity editor模式下读取文件夹资源

    string path = EditorUtility.OpenFolderPanel("Load png Textures", "", "" ...

  3. AlertDailog中的which问题

    在做一个AlertDialog的点击事件设置的时候: AlertDialog.Builder(this).apply { var numberIndex = 0 setTitle("choo ...

  4. F5 api接口开发实战(一)

    本人从18年下旬,开始从事F5负载均衡的自动化开发工作,主要使用python编程语言,开发的F5功能模块为LTM和GTM. F5开发简介 1.F5管理模式 F5的管理模式主要有4种(不包含snmp), ...

  5. 郑政 | 2021软件代码开发技术作业四 | 需求改进&系统设计

    需求改进&系统设计 -------------------------------------------------------------------------------------- ...

  6. Nginx 配置实例-配置虚拟主机

    Nginx 配置实例-配置虚拟主机 配置基于域名的虚拟主机 1. 配置域名为 aaa.domain.com 的虚拟主机 1.1 nginx 中虚拟主机的配置 1.2 相关目录及文件的创建 1.3 验证 ...

  7. CVPR2020无人驾驶论文摘要

    CVPR2020无人驾驶论文摘要 无人 导读/ Starsky是一种比较独特的方案.它是在高速上自动驾驶,第一公里最后一公里采用远程驾驶的模式,Starsky的卡车可以由人类远程操作.没有使用较为昂贵 ...

  8. X-Deep Learning功能模块

    X-Deep Learning功能模块 特征体系 样本 特征 网络 数据准备 样本格式 使用DataReader读取数据 自定义python reader 定义模型 稀疏部分 稠密部分 优化器 训练模 ...

  9. AMD–7nm “Rome”芯片SOC体系结构,支持64核

    AMD–7nm "Rome"芯片SOC体系结构,支持64核 AMD Fully Discloses Zeppelin SOC Architecture Details at ISS ...

  10. Java线程的并发工具类

    Java线程的并发工具类. 一.fork/join 1. Fork-Join原理 在必要的情况下,将一个大任务,拆分(fork)成若干个小任务,然后再将一个个小任务的结果进行汇总(join). 适用场 ...