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 ...
随机推荐
- 009——Matlab调用cftool工具的函数方法
(一)参考文献:http://blog.sina.com.cn/s/blog_4a0a8b5d0100uare.html (二)视频教程:https://v.qq.com/x/page/x30392r ...
- ueditor+flash粘贴word
实现方式: 1.前端引用代码 .粘贴word里面的图片路径是fill://D 这种格式 我理解这种是非浏览器安全的 许多浏览器也不支持 目前项目是用了一种变通的方式: 先把word上传到后台 .poi ...
- 当margin和padding的值是百分比时,如何计算
对元素的margin设置百分数时,百分数是相对于自身包含块的width计算(包含块传送门),不管是margin-top/margin-bottom还是margin-left/margin-right. ...
- 特征工程学习01-sklearn单机特征工程
特征工程学习01-sklearn单机特征工程 小书匠 kindle 0.数据的导入 from sklearn.datasets import load_iris #导入IRIS数据集 iris= ...
- js 读xml文件
参考 http://www.w3school.com.cn/xmldom/dom_document.asp A.xml <?xml version="1.0" encodin ...
- python ros 四元数转欧拉角
#! /usr/bin/python import PyKDL import rospy from sensor_msgs.msg import Imu from nav_msgs.msg impor ...
- python-ros No module named PyKDL
sudo apt-get install ros-indigo-kdl-parser-py http://debian.2.n7.nabble.com/Bug-913803-python3-pykdl ...
- Java基础系列 - HashMap
package com.test3; import java.util.ArrayList; import java.util.HashMap; import java.util.List; impo ...
- MQ Cannot convert from [[B] to [] for GenericMessage
MQ消费端转换报错:主要错误信息:Caused by: org.springframework.messaging.converter.MessageConversionException: Cann ...
- Centos7 安装Redis,报错[adlist.o] Error jemalloc/jemalloc.h: No such file or directory
redis官网 https://redis.io/download 安装 $ wget http://download.redis.io/releases/redis-5.0.4.tar.gz $ t ...