参见ZHT467的题解。

  f[i]表示在i这个集合下的最少分组数和当前组最少的容量。

  从1到(1<<n)-1枚举i,对于每个i枚举它的子奶牛,然后重载运算符计算。

  代码如下

  

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<algorithm>
using namespace std; inline long long read(){
long long num=,f=;
char ch=getchar();
while(!isdigit(ch)){
if(ch=='-') f=-;
ch=getchar();
}
while(isdigit(ch)){
num=num*+ch-'';
ch=getchar();
}
return num*f;
} long long w[];
int Max;
struct Node{
long long cnt,v;
}f[];
int n,W;
inline Node operator +(const Node a,const int b){
return a.v+b<=W?(Node){a.cnt,a.v+b}:(Node){a.cnt+,b};
} inline bool operator <(const Node a,const Node b){
if(a.cnt!=b.cnt) return a.cnt<b.cnt;
return a.v<b.v;
} inline Node min(Node a,Node b){ return a<b?a:b; } int main(){
n=read(),W=read();
Max=(<<n)-;
for(int i=;i<=n;++i) w[i]=read();
for(int i=;i<=Max;++i){
f[i]=(Node){,W};
for(int j=;j<=n;++j){
if(((<<(j-))&i)==) continue;
f[i] = min(f[i],f[(<<(j-))^i]+w[j]);
}
}
printf("%lld",f[Max].cnt+);
return ;
}

最新文章

  1. 使用Newtonsoft.Json.dll(JSON.NET)动态解析JSON、.net 的json的序列化与反序列化(一)
  2. Android编码规范04
  3. ASIHttpRequest 使用理解
  4. Microsoft Help Viewer
  5. App.config的学习笔记
  6. hdu-5680 zxa and set(水题)
  7. WindowsMediaPlayer控件批量添加文件至播放列表
  8. [Swust OJ 1084]--Mzx0821月赛系列之情书(双线程dp)
  9. Oracle性能分析11:系统统计信息
  10. 转 delphi SelText,GetText,SetText用法
  11. LIS算法
  12. POJ 3041 Asteroids / UESTC 253 Asteroids(二分图最大匹配,最小点匹配)
  13. compress.go
  14. 五、JAVA反射、线程
  15. Python项目部署-使用Nginx部署Django项目
  16. js中的所有鼠标事件 键盘事件
  17. AWS EC2 使用root账户密码登陆
  18. MFC 控件使用教程
  19. Cacti Install Error
  20. S导入部门数据 更新父部门、责任人

热门文章

  1. IOS与android
  2. JavaScript数据格式验证探讨
  3. 批处理文件 bat
  4. elasticsearch更新操作问题
  5. 使用ABAP编程实现对微软Office Word文档的操作
  6. Android串口通信
  7. WPF中Canvas使用
  8. vue2.0动画
  9. iview 验证 trigger: &#39;blur,change&#39;, 同时加两个,省的每次还想input 还是 select
  10. SniperOJ-leak-advanced-x86-64