背包+倍增

直接背包跑不过去,那么我们把容量分成二进制,然后原来需要枚举c次就只用枚举log(c)次了,这样还是能组合出任意小于等于c的组合方案

#include<bits/stdc++.h>
using namespace std;
const int N = ;
int n, s;
int b[N], c[N], dp[N];
int main()
{
scanf("%d", &n);
for(int i = ; i <= n; ++i) scanf("%d", &b[i]);
for(int i = ; i <= n; ++i) scanf("%d", &c[i]);
scanf("%d", &s);
memset(dp, 0x3f3f, sizeof(dp));
dp[] = ;
for(int i = ; i <= n; ++i)
{
for(int j = ; j <= c[i]; j <<= )
{
for(int k = s; k >= j * b[i]; --k) dp[k] = min(dp[k], dp[k - j * b[i]] + j);
c[i] -= j;
}
if(c[i]) for(int j = s; j >= c[i] * b[i]; --j) dp[j] = min(dp[j], dp[j - c[i] * b[i]] + c[i]);
}
printf("%d\n", dp[s]);
return ;
}

最新文章

  1. js console 一些拓展技巧
  2. A+B问题 涉及EOF
  3. [ CodeVS冲杯之路 ] P1092
  4. 区间k大数查询
  5. JavaScript 闭包详解
  6. LAMP的编译日志,
  7. Servlet第一篇【介绍Servlet、HTTP协议、WEB目录结构、编写入门Servlet程序、Servlet生命周期】
  8. solrcloud(solr集群版)安装与配置
  9. 关于maven的CoreException: Could not get the value for parameter compilerId for plugin 。。的错误
  10. Linux知识扩展一:执行前为什么加./
  11. Spring Boot + Spring Cloud 实现权限管理系统 后端篇(二十一):服务网关(Zuul)
  12. SQL Server自动备份存储过程和视图的方法
  13. tomcate+keepalived配置双机热备
  14. Vue.js,select中的option用ajax想循环控制值的显示 v-model可以实现但提示报错,这是为什么?
  15. QT信号与槽
  16. 【NOIP 2018】保卫王国(动态dp / 倍增)
  17. Odoo进销存(采购、销售、仓库)入门教程 - 上
  18. hive sql 随机抽样
  19. 【BZOJ3529】[Sdoi2014]数表 莫比乌斯反演+树状数组
  20. SpringFox swagger2 and SpringFox swagger2 UI 接口文档生成与查看

热门文章

  1. AutoEncoders变种
  2. MyBaties 异常之 java.lang.UnsupportedOperationException
  3. HDU 6446 Tree and Permutation(赛后补题)
  4. [luoguP2617] Dynamic Ranking(树状数组 套 主席树 + 离散化)
  5. Form表单的action和onSubmit示例介绍
  6. 常见Unix指令
  7. Ubuntu 16.04出现:&quot;Failed to start /etc/rc.local Compatibility&quot;的问题解决思路
  8. Python标准库:内置函数tuple([iterable])
  9. 【转】winform 程序实现一次只能打开一个该程序
  10. asm volatile (&amp;quot;B .&amp;quot;)