首先比较容易想到是状态压缩DP

令$f[S]$表示选取了集合$S$以后,已经送了最少次数$cnt$且当前电梯剩下的体积$rest$最大(即$f[S]$是一个二元组$(cnt, rest)$)

于是$f[S] = min_{i \in S} f[S - {i}] + v[i]$

重载的$<$和$+$运算详情就请看程序好了,反正就是一个贪心思想,总复杂度$O(n * 2 ^ {n - 1})$

 /**************************************************************
Problem: 2621
User: rausen
Language: C++
Result: Accepted
Time:532 ms
Memory:13092 kb
****************************************************************/ #include <cstdio>
#include <algorithm> using namespace std;
const int N = ;
const int S = << N;
const int inf = 1e9; int n, mx, mxs;
int a[S]; struct data {
int cnt, rest;
data(int _c = , int _r = mx) : cnt(_c), rest(_r) {} inline data operator + (int t) const {
static data res;
res = *this;
res.rest -= t;
if (res.rest < ) ++res.cnt, res.rest += mx;
return res;
} inline bool operator < (const data &d) const {
return cnt == d.cnt ? rest < d.rest : cnt < d.cnt;
}
} f[S]; int main() {
int i, s, t, now;
scanf("%d%d", &n, &mx);
mxs = ( << n) - ;
for (i = ; i <= n; ++i) scanf("%d", &a[ << i - ]);
f[] = data(, mx);
for (s = ; s <= mxs; ++s) {
t = s, f[s] = data(inf, mx);
while (t) {
now = t & (-t);
f[s] = min(f[s], f[s ^ now] + a[now]);
t -= now;
}
}
printf("%d\n", f[mxs].cnt + (f[mxs].rest != mx));
return ;
}

BZOJ2621 [Usaco2012 Mar]Cows in a Skyscraper的更多相关文章

  1. bzoj2621: [Usaco2012 Mar]Cows in a Skyscraper(状压DP)

    第一眼是3^n*n的做法...然而并不可行T T 后来发现对于奶牛的一个状态i,最优情况下剩下那个可以装奶牛的电梯剩下的可用重量是一定的,于是我们设f[i]表示奶牛状态为i的最小电梯数,g[i]为奶牛 ...

  2. 动态规划(状态压缩):BZOJ 2621 [Usaco2012 Mar]Cows in a Skyscraper

      2621: [Usaco2012 Mar]Cows in a Skyscraper Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 303  Sol ...

  3. 2620: [Usaco2012 Mar]Haybale Restacking

    2620: [Usaco2012 Mar]Haybale Restacking Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 201  Solved:  ...

  4. [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper

    洛谷题目链接:[USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper 题目描述 A little known fact about Bessie and friends is ...

  5. 洛谷P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper

    P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper 题目描述 A little known fact about Bessie and friends is ...

  6. [bzoj2621] [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper

    题目链接 状压\(dp\) 根据套路,先设\(f[sta]\)为状态为\(sta\)时所用的最小分组数. 可以发现,这个状态不好转移,无法判断是否可以装下新的一个物品.于是再设一个状态\(g[sta] ...

  7. 洛谷 P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper

    题目描述 A little known fact about Bessie and friends is that they love stair climbing races. A better k ...

  8. [USACO12MAR] 摩天大楼里的奶牛 Cows in a Skyscraper

    题目描述 A little known fact about Bessie and friends is that they love stair climbing races. A better k ...

  9. P3052 [USACO12MAR]摩天大楼里的奶牛Cows in a Skyscraper 状压dp

    这个状压dp其实很明显,n < 18写在前面了当然是状压.状态其实也很好想,但是有点问题,就是如何判断空间是否够大. 再单开一个g数组,存剩余空间就行了. 题干: 题目描述 A little k ...

随机推荐

  1. python内置函数的归集

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明. Python内置(built-in)函数随着python解释器的运行而创建.在Pytho ...

  2. 关于line box,inline box,line-height,vertical-align之间的关系

    1.content area 围绕着文字的一种box,高度由font-size和font-family决定.在chrome控制器里,你用鼠标志向某个内敛元素,显示的高度值. 2.inline box的 ...

  3. ScriptX.cab打印控件的使用,控件文件里有

    1.在head里添加 <object id="factory" style="display:none;" viewastext classid=&quo ...

  4. mysql 聚集函数需要注意的问题

    1.当没有记录的时候,使用聚集函数,会导致出现一条记录,记录的取值都是NULL,如下:mysql> select name from student where name='David';Emp ...

  5. Object Pascal 语言基础

    Delphi 是以Object Pascal 语言为基础的可视化开发工具,所以要学好Delphi,首先要掌握的就是Object Pascal 语言.Object Pascal语言是Pascal之父在1 ...

  6. iOS 开发之 Xcode6 打包生成ipa给测试

    Xcode 6正式版Version 6.0.1 (6A317)已经放出Mac AppStore,之前为了体验swift也安装过beta版,但是并没有注意到6系Xcode对于导出ipa的变化,更新正式版 ...

  7. MyBatis——优化MyBatis配置文件中的配置

    原文:http://www.cnblogs.com/xdp-gacl/p/4264301.html 一.连接数据库的配置单独放在一个properties文件中 之前,我们是直接将数据库的连接配置信息写 ...

  8. D3.js 第一个程序 HelloWorld

    一.HTML 是怎么输出 HelloWorld 的 <html> <head> <meta charset="utf-8"> <title ...

  9. 转!数据库连接池概念、种类、配置(DBCP\C3P0\JndI与Tomact配置连接池)

    数据库连接池概念.种类.配置(DBCP\C3P0\JndI与Tomact配置连接池) 一.DBCP 连接:DBCP 连接池是 Apache 软件基金组织下的一个开源连接池实现. 需要的 java 包c ...

  10. jquery select选中项 赋值

    $("flag").attr("value",flag); $("#flag").find("option:selected&qu ...