1531: [POI2005]Bank notes

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 521  Solved: 285
[Submit][Status][Discuss]

Description

Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我们想要凑出面值k求最少要用多少个硬币.

Input

第一行一个数
n, 1 <= n <= 200. 接下来一行 n 个整数b1, b2,..., bn, 1 <= b1 < b2
< ... < b n <= 20 000, 第三行 n 个整数c1, c2,..., cn, 1 <= ci
<= 20 000, 表示每种硬币的个数.最后一行一个数k – 表示要凑的面值数量, 1 <= k <= 20 000.

Output

第一行一个数表示最少需要付的硬币数

Sample Input

3
2 3 5
2 2 1
10

Sample Output

3
题解:
二进制优化多重背包板子(我这都不会,我太弱啦!
网上找的一个比较美观的模板
#pragma GCC optimize("O2")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<limits.h>
#include<ctime>
#define N 100001
typedef long long ll;
const int inf=999999999;
const int maxn=2017;
using namespace std;
inline int read()
{
int f=1,x=0;char ch=getchar();
while(ch>'9'|ch<'0')
{
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0')
{
x=(x<<3)+(x<<1)+ch-'0';
ch=getchar();
}
return f*x;
}
int b[N],c[N],dp[N];
int main()
{
int n=read();
for(int i=1;i<=n;i++)
{
b[i]=read();
}
for(int i=1;i<=n;i++)
c[i]=read();
int m=read();
memset(dp,0x3f,sizeof(dp));
dp[0]=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=c[i];j<<=1)
{
for(int k=m;k>=b[i]*j;k--)
dp[k]=min(dp[k],dp[k-b[i]*j]+j);c[i]-=j;
if(c[i])
for(int k=m;k>=b[i]*c[i];k--)
dp[k]=min(dp[k],dp[k-c[i]*b[i]]+c[i]);
}
}
printf("%d\n",dp[m]);
}

bzoj1531: [POI2005]Bank notes(多重背包)的更多相关文章

  1. 【bzoj1531】[POI2005]Bank notes 多重背包dp

    题目描述 Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我们想要凑出面值 ...

  2. bzoj1531[POI2005]Bank notes 单调队列优化dp

    1531: [POI2005]Bank notes Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 559  Solved: 310[Submit][Sta ...

  3. 2018.09.08 bzoj1531: [POI2005]Bank notes(二进制拆分优化背包)

    传送门 显然不能直接写多重背包. 这题可以用二进制拆分/单调队列优化(感觉二进制好写). 所谓二进制优化,就是把1~c[i]拆分成20,21,...2t,c[i]−2t+1+1" role= ...

  4. bzoj1531: [POI2005]Bank notes

    Description Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我 ...

  5. bzoj 1531 Bank notes 多重背包/单调队列

    多重背包二进制优化终于写了一次,注意j的边界条件啊,疯狂RE(还是自己太菜了啊啊)最辣的辣鸡 #include<bits/stdc++.h> using namespace std; in ...

  6. BZOJ 1531: [POI2005]Bank notes( 背包 )

    多重背包... ---------------------------------------------------------------------------- #include<bit ...

  7. 1531: [POI2005]Bank notes二进制优化(c++)

    Description Byteotian Bit Bank (BBB) 拥有一套先进的货币系统,这个系统一共有n种面值的硬币,面值分别为b1, b2,..., bn. 但是每种硬币有数量限制,现在我 ...

  8. ●BZOJ 1531 [POI2005]Bank notes

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=1531 题解: 单调队列优化多重背包DP (弱弱的我今天总算是把这个坑给填了...) 令V[i ...

  9. [POI2005]Bank notes

    link 试题分析 我们发现此题是一个十分简单的多重背包.但是按照朴素写法会超时.所以要去考虑优化. 我们发现我们若$W=7$,可以拆成$1+2+4$,不用每次$1+1+1+1+1+1+1$,从$N$ ...

随机推荐

  1. windows下KafkaOffsetMonitor下载及安装

    KafkaOffsetMonitor是一个可视化工具的jar包,如KafkaOffsetMonitor-assembly-0.2.1.jar,用来来监控kafka的使用状态. 一.下载地址 https ...

  2. ubuntu 出错 /etc/sudoers is world writable

    如果改变了这个,目录的权限sodu就不能用了,当你再使用sodu命令就会爆如下问题: sudo: /etc/sudoers is world writablesudo: no valid sudoer ...

  3. python字符串之split

    函数:split() Python中有split()和os.path.split()两个函数,具体作用如下:split():拆分字符串.通过指定分隔符对字符串进行切片,并返回分割后的字符串列表(lis ...

  4. Git 将本地库添加到远程仓库

    git remote add origin ssh://admin@127.0.0.1:29418/Prjs/prj1.git git push -u origin master

  5. 前后台交互经常使用的技术汇总(后台:Java技术,前台:Js或者Jquery)

    1:由于针对特定的前后台交互用到的知识总结,所以不大量贴代码,主要给出思路,方便自己以后脑补和技术总结,当然也希望可以帮助到别人. 后台Json和其他格式转化,之前总结过Json和对象,集合,字符串的 ...

  6. 学习笔记: 反射应用、原理,完成扩展,emit动态代码

    using Ruanmou.DB.Interface; using Ruanmou.DB.MySql; using Ruanmou.DB.SqlServer; using Ruanmou.Model; ...

  7. 错误 java.lang.ClassCastException: com.xx cannot be cast to ResourceBundle

    出现错误: java.lang.ClassCastException: com.xxx cannot be cast to ResourceBundle 百度搜索错误,没有结果.谷歌搜索:http:/ ...

  8. Flink--将表转换为DataStream或DataSet

    A Table可以转换成a DataStream或DataSet.通过这种方式,可以在Table API或SQL查询的结果上运行自定义的DataStream或DataSet程序 将表转换为DataSt ...

  9. Flink--输入数据集Data Sources

    flink在批处理中常见的source flink在批处理中常见的source主要有两大类. 1.基于本地集合的source(Collection-based-source) 2.基于文件的sourc ...

  10. JQ JS复制到剪贴板

    示例: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...