bzoj1531
2024-09-30 04:26:10
背包+倍增
直接背包跑不过去,那么我们把容量分成二进制,然后原来需要枚举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 ;
}
最新文章
- js console 一些拓展技巧
- A+B问题 涉及EOF
- [ CodeVS冲杯之路 ] P1092
- 区间k大数查询
- JavaScript 闭包详解
- LAMP的编译日志,
- Servlet第一篇【介绍Servlet、HTTP协议、WEB目录结构、编写入门Servlet程序、Servlet生命周期】
- solrcloud(solr集群版)安装与配置
- 关于maven的CoreException: Could not get the value for parameter compilerId for plugin 。。的错误
- Linux知识扩展一:执行前为什么加./
- Spring Boot + Spring Cloud 实现权限管理系统 后端篇(二十一):服务网关(Zuul)
- SQL Server自动备份存储过程和视图的方法
- tomcate+keepalived配置双机热备
- Vue.js,select中的option用ajax想循环控制值的显示 v-model可以实现但提示报错,这是为什么?
- QT信号与槽
- 【NOIP 2018】保卫王国(动态dp / 倍增)
- Odoo进销存(采购、销售、仓库)入门教程 - 上
- hive sql 随机抽样
- 【BZOJ3529】[Sdoi2014]数表 莫比乌斯反演+树状数组
- SpringFox swagger2 and SpringFox swagger2 UI 接口文档生成与查看
热门文章
- AutoEncoders变种
- MyBaties 异常之 java.lang.UnsupportedOperationException
- HDU 6446 Tree and Permutation(赛后补题)
- [luoguP2617] Dynamic Ranking(树状数组 套 主席树 + 离散化)
- Form表单的action和onSubmit示例介绍
- 常见Unix指令
- Ubuntu 16.04出现:";Failed to start /etc/rc.local Compatibility";的问题解决思路
- Python标准库:内置函数tuple([iterable])
- 【转】winform 程序实现一次只能打开一个该程序
- asm volatile (&;quot;B .&;quot;)