leetcode1105 Filling Bookcase Shelves
思路:
dp[i]表示摆放好前i本书所需要的最小代价。
实现:
class Solution
{
public:
int minHeightShelves(vector<vector<int>>& books, int shelf_width)
{
int n = books.size();
vector<int> dp(n + , );
dp[] = ; dp[] = books[][];
for (int i = ; i <= n; i++)
{
dp[i] = dp[i - ] + books[i - ][];
int sum = books[i - ][], maxn = books[i - ][];
for (int j = i - ; j >= ; j--)
{
if (sum + books[j - ][] > shelf_width) break;
maxn = max(maxn, books[j - ][]);
dp[i] = min(dp[i], dp[j - ] + maxn);
sum += books[j - ][];
}
}
return dp[n];
}
}
leetcode1105 Filling Bookcase Shelves的更多相关文章
- LeetCode 1105. Filling Bookcase Shelves
原题链接在这里:https://leetcode.com/problems/filling-bookcase-shelves/ 题目: We have a sequence of books: the ...
- 【leetcode】1105. Filling Bookcase Shelves
题目如下: We have a sequence of books: the i-th book has thickness books[i][0] and height books[i][1]. W ...
- 【Codeforces-707D】Persistent Bookcase DFS + 线段树
D. Persistent Bookcase Recently in school Alina has learned what are the persistent data structures: ...
- Codeforces Round #368 (Div. 2) D. Persistent Bookcase
Persistent Bookcase Problem Description: Recently in school Alina has learned what are the persisten ...
- Persistent Bookcase
Persistent Bookcase time limit per test 2 seconds memory limit per test 512 megabytes input standard ...
- Codeforces Round #368 (Div. 2) D. Persistent Bookcase 离线 暴力
D. Persistent Bookcase 题目连接: http://www.codeforces.com/contest/707/problem/D Description Recently in ...
- codeforces 707D:Persistent Bookcase
Description Recently in school Alina has learned what are the persistent data structures: they are d ...
- codeforces 707D D. Persistent Bookcase(dfs)
题目链接: D. Persistent Bookcase time limit per test 2 seconds memory limit per test 512 megabytes input ...
- Codeforces-707D:Persistent Bookcase (离线处理特殊的可持久化问题&&Bitset)
Recently in school Alina has learned what are the persistent data structures: they are data structur ...
随机推荐
- [CSS] Change the off-axis Alignment of a Flexed Container with `align-items`
We changed the axis layout with 'justify-content', and the "off axis" layout is controlled ...
- [Dart] splitMapJoin
var str3 = '''Multi Line String'''; print( str3.splitMapJoin( RegExp(r'^', multiLine: true), // Matc ...
- php数据类型之查看和判断数据类型
我们知道了一个数据的类型,才能进行下一步操作.后面的时候,大家可以学习到更多的知识——自定义功能(函数). 我们来做一个场景模拟:(注:眼前不用会写这个函数,以后会教大家) 假设,我们可以写一个智能的 ...
- 分治 FFT学习笔记
先给一道luogu板子题:P4721 [模板]分治 FFT 今天模拟有道题的部分分做法是分治fft,于是就学了一下.感觉不是很难,国赛上如果推出式子的话应该能写出来. 分治fft用来解决这么一个式子\ ...
- nginx + keepalived双活配置
一.安装nginx 我们这边默认安装的nginx的是1.12.2的版本,所以我们需要安装1.16.1版本的nginx的,才好,所以我们这边先更新yum源,步骤如下: 1.添加yum源: [root@s ...
- NodeJs的Event Loop
我们之前谈过浏览器的Event Loop:https://www.cnblogs.com/amiezhang/p/11349450.html 简单来说,就是每执行一个宏任务,就去执行微任务队列,直到清 ...
- jmeter+ant+jenkins构建自动化测试
背景目的: 持续更新.... 参考文档:https://blog.csdn.net/cherish0123/article/details/79339732
- Selenium 八种元素定位方法
前言: 我们在做WEB自动化时,最根本的就是操作页面上的元素,首先我们要能找到这些元素,然后才能操作这些元素.工具或代码无法像我们测试人员一样用肉眼来分辨页面上的元素.那么我们怎么来定位他们呢? 在学 ...
- OpenFOAM中的基本变量快速认知【转载】
转载自:http://blog.sina.com.cn/s/blog_a0b4201d0102vsf9.html label 实际上就是整型数据的变体,int,OF对它进行了包装,以适应32或64位系 ...
- Hive和Hadoop
我最近研究了hive的相关技术,有点心得,这里和大家分享下. 首先我们要知道hive到底是做什么的.下面这几段文字很好的描述了hive的特性: 1.hive是基于Hadoop的一个数据仓库工具,可以将 ...