max-sum-of-sub-matrix-no-larger-than-k
根据上一篇文章提到的参考文档:
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的更多相关文章
- HDU-1003 Max Sum(动态规划,最长字段和问题)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- [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 ...
- 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 ...
- 【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 ...
- 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 ...
- [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 ...
- 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 ...
- 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 ...
- [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 ...
- 【LeetCode】363. Max Sum of Rectangle No Larger Than K 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址: https://leetcode.com/problems/max-sum- ...
随机推荐
- Ionic Tabs
Ionic 默认的 Tabs 模板 ,Android的在上方,IOS的在下方.在www/js/app.js修改配置,添加一个变量,再修改相应属性: .config(function($statePro ...
- 关于ecshop的mobile里user.php登录和注册验证码不显示
在做ecshop模板的时候由于user.php里的登录和注册是在一个页面里切换的,这就致使这里的登录和注册里的验证码不显示 找到mobile/themesmobile/ecshoptemplate_m ...
- mysql proxy代理安装和配置
mysql proxy代理安装和配置 服务器说明: 192.168.1.219 mysql主库(主从复制) 192.168.1.177 mysql从库(主从复制) 192.168.1.202 ...
- CSU - 2055 Wells‘s Lottery
Description As is known to all, Wells is impoverished. When God heard that, God decide to help the p ...
- NetCore控制台实现自定义CommandLine功能
命令行科普: 例如输入: trans 123 456 789 -r 123 -r 789上面例子中:trans是Command,123 456 789是CommandArgument,-r之后的都是C ...
- [leetcode tree]102. Binary Tree Level Order Traversal
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...
- 【Performance】chrome调试面板
本篇文章以chrome版本67.0.3396.99为例,说明性能方面的调试.
- scrapy爬虫,爬取图片
一.scrapy的安装: 本文基于Anacoda3, Anacoda2和3如何同时安装? 将Anacoda3安装在C:\ProgramData\Anaconda2\envs文件夹中即可. 如何用con ...
- android 不失真 显示 超高清 图片 长图
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha 通过计算 位图工厂.选项 对象的 inSamleSize 值 等比压缩 图片. 使用 ...
- bzoj1814: Ural 1519 Formula 1 动态规划 插头dp
http://acm.timus.ru/problem.aspx?space=1&num=1519 题目描述 一个 m * n 的棋盘,有的格子存在障碍,求经过所有非障碍格子的哈密顿回路个数. ...