首页 技术 正文
技术 2022年11月7日
0 收藏 958 点赞 543 浏览 840 个字

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 多重背包,转化为01背包做,但是需要加上二进制优化,不然会超时。

 #include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
int f[]={},b[]={},c[]={},s[]={},w[]={}; int main()
{
int n=;
cin>>n;
for (int i=;i<=n;i++)
cin>>b[i];
for (int i=;i<=n;i++)
cin>>c[i];
int tot=;
int now=,x=;
while (now<=n)
{
x=;
while (c[now]-x>)
{
++tot;
s[tot]=x*b[now];
w[tot]=x;
c[now]-=x;
x=x*;
}
if (c[now]>)
{
++tot;
s[tot]=c[now]*b[now];
w[tot]=c[now];
}
++now;
}
int k=;
memset(f,,sizeof(f));
cin>>k;
f[]=;
for (int i=;i<=tot;i++)
for (int j=k;j>=s[i];j--)
f[j]=min(f[j-s[i]]+w[i],f[j]);
cout<<f[k];
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,078
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,553
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,402
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,177
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,814
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898