根据上一篇文章提到的参考文档:

https://leetcode.com/discuss/109749/accepted-c-codes-with-explanation-and-references

我实现的解法,用了一个sum_max,不再另设res。

class Solution {
public:
int maxSumSubmatrix(vector<vector<int>>& matrix, int K) {
int sum_max = INT_MIN;
int rlen = matrix.size();
int clen = matrix[].size(); for (int i=; i<clen; i++) {
vector<int> tmp_vec(rlen, );
for (int j=i; j<clen; j++) {
for (int k=; k<rlen; k++) {
tmp_vec[k] += matrix[k][j];
} set<int> cur_max_set;
int cur_max = ;
for (int k=; k<rlen; k++) {
cur_max += tmp_vec[k];
if (cur_max <= K) {
sum_max = max(sum_max, cur_max);
}
set<int>::iterator iter = cur_max_set.lower_bound(cur_max - K);
if (iter != cur_max_set.end()) {
sum_max = max(sum_max, cur_max-*iter);
}
cur_max_set.insert(cur_max);
}
}
}
return sum_max;
}
};
27 / 27 test cases passed.
Status:

Accepted

Runtime: 1016 ms

max-sum-of-sub-matrix-no-larger-than-k的更多相关文章

  1. HDU-1003 Max Sum(动态规划,最长字段和问题)

    Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  2. [LeetCode] Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K

    Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...

  3. Leetcode: Max Sum of Rectangle No Larger Than K

    Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...

  4. 【leetcode】363. Max Sum of Rectangle No Larger Than K

    题目描述: Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the ma ...

  5. Max Sum of Rectangle No Larger Than K

    Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...

  6. [Swift]LeetCode363. 矩形区域不超过 K 的最大数值和 | Max Sum of Rectangle No Larger Than K

    Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...

  7. 363. Max Sum of Rectangle No Larger Than K

    /* * 363. Max Sum of Rectangle No Larger Than K * 2016-7-15 by Mingyang */ public int maxSumSubmatri ...

  8. 363 Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K

    Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...

  9. [LeetCode] 363. Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K

    Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...

  10. 【LeetCode】363. Max Sum of Rectangle No Larger Than K 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/max-sum- ...

随机推荐

  1. FPGA+ARM or FPGA+DSP?

    网上有人说.现在的FPGA,ARM功能已经强大到无需DSP协助处理了,未来DSP会不会消声灭迹?是DSP取代FPGA和ARM,还是ARM,FPGA取代DSP呢?担心好不容易学精了DSP,结果DSP变成 ...

  2. Spring Security权限控制

    Spring Security官网 : https://projects.spring.io/spring-security/ Spring Security简介: Spring Security是一 ...

  3. python获取当前系统的桌面的路径

    一,用内置的winreg(推荐) import winregdef get_desktop():    key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,\  ...

  4. oslo.config

    cfg Module来自于OpenStack中的重要的基础组件oslo.config,通过cfg Module可以用来通过命令行或者是配置文件来配置一些options, 对于每一个选项使用Opt类或者 ...

  5. 我们不能把JavaScript作为一个全功能的编程语言。它缺乏以下重要特征

    客户端JavaScript不允许读或写文件.这已被保存的安全原因. JavaScript不能用于网络的应用,因为没有这样的支持. JavaScript没有任何多线程或多处理器的能力.

  6. BZOJ 5059: 前鬼后鬼的守护 可并堆 左偏树 数学

    https://www.lydsy.com/JudgeOnline/problem.php?id=5059 题意:将原序列{ai}改为一个递增序列{ai1}并且使得abs(ai-ai1)的和最小. 如 ...

  7. WinlogonHack获取系统密码

    实验环境: win03 sp1 Gina.dll与Msgina.dll Gina.dll在NT/2000中交互式的登陆支持是由WinLogon调用Gina.dll实现的,Gina.dll提供了一个交互 ...

  8. 本地文件包含漏洞(LFI漏洞)

    0x00 前言 本文的主要目的是分享在服务器遭受文件包含漏洞时,使用各种技术对Web服务器进行攻击的想法. 我们都知道LFI漏洞允许用户通过在URL中包括一个文件.在本文中,我使用了bWAPP和DVW ...

  9. windows下配置ssh(FreeSSHD + putty)

    windows下配置ssh(FreeSSHD + putty): 1.关于配置过程找到一篇很好的博客,推荐大家先好好看一下,这篇博文解决了大方向问题. 地址:http://blog.csdn.net/ ...

  10. Elasticsearch中document的基础知识

    写在前面的话:读书破万卷,编码如有神-------------------------------------------------------------------- 参考内容: <Ela ...