[USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper——[状压DP]

这是一道关于奶牛和摩天大楼的动态规划问题。给定每头奶牛的重量和电梯的最大载重,求解如何用最少的电梯行程将所有奶牛送回地面。通过状态压缩动态规划方法解决,限制条件是奶牛数量不超过18,电梯最大载重量不超过100,000,000磅。" 126097318,11412145,前端面试必备:61道常见题目详解,"['前端开发', 'JavaScript', '面试准备']
摘要由CSDN通过智能技术生成

【原题】
A little known fact about Bessie and friends is that they love stair climbing races. A better known fact is that cows really don’t like going down stairs. So after the cows finish racing to the top of their favorite skyscraper, they had a problem. Refusing to climb back down using the stairs, the cows are forced to use the elevator in order to get back to the ground floor.

The elevator has a maximum weight capacity of W (1 <= W <= 100,000,000) pounds and cow i weighs C_i (1 <= C_i <= W) pounds. Please help Bessie figure out how to get all the N (1 <= N <= 18) of the cows to the ground floor using the least number of elevator rides. The sum of the weights of the cows on each elevator ride must be no larger than W.

【题目翻译】
有n头奶牛 ( 1 ≤ n ≤ 18 ) (1≤n≤18) (1n18),每一栋摩天大楼容量为W ( 1 ≤ W ≤ 1 0 8 ) , (1≤W≤10^8), (1W108),,每头奶牛有一个质量c[i] ( 1 ≤ c [ i ] ≤ W ) (1≤c[i]≤W) (1c[i]W),问将所有的奶牛安置需要几栋摩天大楼。

【输入格式】
第一行,两个数n,W
接下来n行,每行一个数c[i]

【输出格式】
一个数,安置所有的奶牛最少需要几栋摩天大楼。

S a m p l e &ThickSpace; I n p u t Sample\;Input SampleInput

4 10
5
6
3
7

S a m p l e &ThickSpace; O u t p u t Sample\;Output SampleOutput

3

【题意分析】
经典的状压DP题。 n ≤ 18 n≤18 n18可以卡掉大部分爆搜(超神搜索请无视)

d p [ i ] dp[i] dp[i]表示状态为 i i i时最少需要几栋摩天大楼。
r e s t [ i ] rest[i]

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值