传送门

输出被阉割了。

只输出最少分的组数即可。

f 数组为结构体

f[S].cnt 表示集合 S 最少的分组数

f[S].v  表示集合 S 最少分组数下当前组所用的最少容量

f[S] = min(f[S], f[S - i] + a[i]) (i ∈ S)

运算重载一下即可。

——代码

 #include <cstdio>
#include <iostream> int n, m, w;
int a[];
struct qwq
{
int cnt, v;
qwq(int cnt = , int v = ) : cnt(cnt), v(v) {}
}f[ << ]; inline qwq operator + (const qwq x, const int d)
{
return x.v + d <= w ? qwq(x.cnt, x.v + d) : qwq(x.cnt + , d);
} inline bool operator < (const qwq x, const qwq y)
{
return x.cnt == y.cnt ? x.v < y.v : x.cnt < y.cnt;
} inline qwq min(qwq x, qwq y)
{
return x < y ? x : y;
} inline int read()
{
int x = , f = ;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -;
for(; isdigit(ch); ch = getchar()) x = (x << ) + (x << ) + ch - '';
return x * f;
} int main()
{
int i, S;
n = read();
w = read();
m = ( << n) - ;
for(i = ; i <= n; i++) a[i] = read();
for(S = ; S <= m; S++)
{
f[S] = qwq(1e9, w);
for(i = ; i <= n; i++)
{
if(!(( << i - ) & S)) continue;
f[S] = min(f[S], f[( << i - ) ^ S] + a[i]);
}
}
printf("%d\n", f[m].cnt + );
return ;
}

最新文章

  1. github入门到上传本地项目
  2. HTML学习笔记——标签
  3. Dump类型说明
  4. July 18th, Week 30th Monday, 2016
  5. Yii源码阅读笔记(五)
  6. 表单和验证事件以及marquee标签
  7. MySQL常用工具
  8. Windows命令行(DOS命令)教程-6 (转载)http://arch.pconline.com.cn//pcedu/rookie/basic/10111/15325_5.html
  9. android设置图片变化的四种效果代码
  10. zookeeper常用sehll命令
  11. C#8.0可空引用类型的使用注意要点
  12. windows安全更新程序(KB4093112) 安装失败 错误0x80070011
  13. 合并多个对象并且去重的2种写法(es6)
  14. HTTPS IP直连问题小结
  15. Java坦克大战(一)
  16. 通过mysql写入php一句话木马
  17. (1)什么是web框架和http协议
  18. django模板系统(下)
  19. [转]Linux内核源码详解--iostat
  20. RF根据单个/多个output文件重新生成log和report文件

热门文章

  1. bzoj1216 操作系统(优先队列模拟)
  2. 公司6:JrVue重用布局
  3. 转 awr自动收集脚本
  4. SQL数据库——静态成员
  5. NodeJs学习记录(四)初学阶段关于app.js里的一些重要配置
  6. arp学习笔记(linux高性能服务编程)
  7. leetcode126 Word Ladder II
  8. XAMPP--Apache服务无法启动问题定位及处理
  9. JavaScript判断
  10. RabbitMQ系列(七)--批量消息和延时消息