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 ...
随机推荐
- [ARIA] Accessible animations with reduced motion
Animations can make people sick, or worse! By adding animation toggles and listening in to the user' ...
- [GraphQL] Query GraphQL Interface Types in GraphQL Playground
Interfaces are similar to Unions in that they provide a mechanism for dealing with different types o ...
- 010——C#选择文件路径
(一)具体教程查看:011——C#创建ECXEL文件(附教程) (二)代码:foldPath 就是获取到的文件路径 private void button1_Click(object sender, ...
- [Luogu] 教主的魔法
https://www.luogu.org/problemnew/show/P2801 分块 对于每一块进行排序存储在另一个数组中 二分查询 #include<iostream> #inc ...
- spring boot 扫描 其他jar包里面的 mapper xml
启动类配置扫描 goods.mapper为当前项目mapper路径 ,common.mpper为其他jar包. 1. 2.mybatis.mapper-locations=classpath*:map ...
- geometry_msgs/PoseStamped 类型的变量的构造
#navpoint.msg geometry_msgs/PoseStamped target_pose uint8 floor uint8 type target_pose 的类型为geometry_ ...
- MySQL 5.7:聊聊sql_mode
1.sql_mode=only_full_group_by 导致的语法错误问题 MySQLSyntaxErrorException Caused by: com.mysql.jdbc.exceptio ...
- CF786E ALT
题意 有一棵 \(n\) 个点的树和 \(m\) 个人,第 \(i\) 个人从 \(u_i\) 走到 \(v_i\) 现在要发宠物,要求一个人要么他自己发到宠物,要么他走的路径上的都有宠物. 求最小代 ...
- hbase单点安装
系统环境:centos 6 软件包: hbase版本:hbase-1.4.8-bin.tar.gz 下载地址:wget http://mirror.bit.edu.cn/apache/hba ...
- yarn-site.xml 基本配置参考
以下只是对yarn配置文件(yarn.site.xml)简单的一个配置 <configuration> <!-- rm失联后重新链接的时间 --> <property&g ...