The Fewest Coins
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 6299   Accepted: 1922

Description

Farmer John has gone to town to buy some farm supplies. Being a very efficient man, he always pays for his goods in such a way that the smallest number of coins changes hands, i.e., the number of coins he uses to pay plus the number of coins he receives in change is minimized. Help him to determine what this minimum number is.

FJ wants to buy T (1 ≤ T ≤ 10,000) cents of supplies. The currency system has N (1 ≤ N ≤ 100) different coins, with values V1V2, ..., VN (1 ≤ Vi ≤ 120). Farmer John is carrying C1 coins of value V1C2 coins of value V2, ...., and CN coins of value VN (0 ≤ Ci ≤ 10,000). The shopkeeper has an unlimited supply of all the coins, and always makes change in the most efficient manner (although Farmer John must be sure to pay in a way that makes it possible to make the correct change).

Input

Line 1: Two space-separated integers: N and T
Line 2: N space-separated integers, respectively V1V2, ..., VN coins (V1, ...VN
Line 3: N space-separated integers, respectively C1C2, ..., CN

Output

Line 1: A line containing a single integer, the minimum number of coins involved in a payment and change-making. If it is impossible for Farmer John to pay and receive exact change, output -1.

Sample Input

3 70
5 25 50
5 2 1

Sample Output

3

Hint

Farmer John pays 75 cents using a 50 cents and a 25 cents coin, and receives a 5 cents coin in change, for a total of 3 coins used in the transaction.

Source


题意:FJ每种硬币有限,售货员无限,最小化交易用的硬币数

FJ多重背包,售货员完全背包
min一下f[i+m]+d[i]
NOTICE:体积选多大呢?
有一个证明,如果John的付款数大于了maxv*maxv+m,即付硬币的数目大于了maxv,根据鸽笼原理,至少有两个的和对maxv取模的值相等,也就是说,这部分硬币能够用更少的maxv来代替。证毕。
看不懂算了
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=,M=*+1e4+,INF=1e9;
int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int n,m,om,v[N],c[N],ans=INF,mxv=;
int f[M],d[M];
inline void zp(int v,int w){
for(int j=m;j>=v;j--) f[j]=min(f[j],f[j-v]+w);
}
inline void cp(int v){
for(int j=v;j<=m;j++) f[j]=min(f[j],f[j-v]+);
}
inline void mp(int v,int c){
if(v*c>=m){cp(v);return;}
int k=;
while(k<c){
zp(k*v,k);
c-=k;
k*=;
}
zp(c*v,c);
}
int main(){
n=read();m=om=read();
for(int i=;i<=n;i++) v[i]=read(),mxv=max(mxv,v[i]);m+=mxv*mxv;
for(int i=;i<=n;i++) c[i]=read(); for(int i=;i<=m;i++) d[i]=INF;d[]=;
for(int i=;i<=n;i++)
for(int j=v[i];j<=m;j++)
d[j]=min(d[j],d[j-v[i]]+);
for(int i=;i<=m;i++) f[i]=INF;f[]=;
for(int i=;i<=n;i++) mp(v[i],c[i]);
for(int i=;i<=m-om;i++)
if(f[i+om]+d[i]<ans) ans=f[i+om]+d[i];
if(ans>=INF) printf("-1");
else printf("%d",ans);
}
 

POJ3260The Fewest Coins[背包]的更多相关文章

  1. POJ3260——The Fewest Coins(多重背包+完全背包)

    The Fewest Coins DescriptionFarmer John has gone to town to buy some farm supplies. Being a very eff ...

  2. POJ 3260 The Fewest Coins(多重背包+全然背包)

    POJ 3260 The Fewest Coins(多重背包+全然背包) http://poj.org/problem?id=3260 题意: John要去买价值为m的商品. 如今的货币系统有n种货币 ...

  3. POJ 3260 The Fewest Coins(完全背包+多重背包=混合背包)

    题目代号:POJ 3260 题目链接:http://poj.org/problem?id=3260 The Fewest Coins Time Limit: 2000MS Memory Limit: ...

  4. The Fewest Coins POJ - 3260

    The Fewest Coins POJ - 3260 完全背包+多重背包.基本思路是先通过背包分开求出"付出"指定数量钱和"找"指定数量钱时用的硬币数量最小值 ...

  5. (混合背包 多重背包+完全背包)The Fewest Coins (poj 3260)

    http://poj.org/problem?id=3260   Description Farmer John has gone to town to buy some farm supplies. ...

  6. POJ3260:The Fewest Coins(混合背包)

    Description Farmer John has gone to town to buy some farm supplies. Being a very efficient man, he a ...

  7. 洛谷P2851 [USACO06DEC]最少的硬币The Fewest Coins(完全背包+多重背包)

    题目描述 Farmer John has gone to town to buy some farm supplies. Being a very efficient man, he always p ...

  8. POJ 3260 The Fewest Coins 最少硬币个数(完全背包+多重背包,混合型)

    题意:FJ身上有各种硬币,但是要买m元的东西,想用最少的硬币个数去买,且找回的硬币数量也是最少(老板会按照最少的量自动找钱),即掏出的硬币和收到的硬币个数最少. 思路:老板会自动找钱,且按最少的找,硬 ...

  9. 完全背包和多重背包的混合 F - The Fewest Coins

    http://poj.org/problem?id=3260 这个题目有点小难,我开始没什么头绪,感觉很乱. 后来看了题解,感觉豁然开朗. 题目大意:就是这个人去买东西,东西的价格是T,这个人拥有的纸 ...

随机推荐

  1. 小白的CSS基础学习

    CSS定义: CSS全称为“层叠样式表 (Cascading Style Sheets)”,它主要是用于定义HTML内容在浏览器内的显示样式. CSS代码语法: css样式选择组成部分:选择符+声明( ...

  2. Atitit.复合文档的格式 标准化格式

    Atitit.复合文档的格式 标准化格式 1. Docfile1 2. Iso   Cdf  cd file1 3. Zip1 4. Ooxml1 5. Odf  :OpenDocument Form ...

  3. bootstrap的一些资源

    http://www.cnblogs.com/landeanfen/p/5461849.html 总结了时间,加载,自动增加图片选择,等bootstap控件 http://www.cnblogs.co ...

  4. OC 中的block存储位置

    以下所有在ARC情况下: 一.block块的存储位置(block块入口地址):可能存放在2个地方:代码区.堆区(程序分5个区,还有常量区.全局区和栈区,对于MRC情况下代码还可能存在栈区.关于分区详细 ...

  5. IOS开发之代理的设计小技巧

    1.关于代理对象的设计小技巧 在设计一个类,需要通过代理和协议来从外部获取需要的动态的数据.那么在这里设计使用代理会有两种方法. <第一种方法> 也是比较常见的: 在你设计的类中,声明一个 ...

  6. IDEA中,将文件夹加入classpath

    加载文件时遇到某些文件加载不到,可能是因为该文件不在classpath中. 加入方法: 1.File - Project Structure 2.如图 modules - 选择需要加入的文件夹, 点击 ...

  7. nexus搭建maven私服

    下载nexus 首先,从以下地址下载nexus: http://www.sonatype.com/download-oss-sonatype 选择下载nexus-2.13.0-01-bundle.ta ...

  8. js技术发展

    将.NET代码编译为JavaScript 你可以使用如下工具将C#.F#以及其他.NET代码编译为JavaScript代码. Apps in Motion:允许使用C#来构建可以运行在任何设备上的We ...

  9. HttpServletResponse对象 学习

    Web服务器收到客户端的http请求,会针对每一次请求,分别创建一个用于代表请求的request对象.和代表响应的response对象.request和response对象即然代表请求和响应,那我们要 ...

  10. Oracle行内链接不会引起USER_TABLES中CHAIN_CNT值变化

    前几天和群里网友讨论一个关于行内链接(intra-block chaining)的问题,问题非常有意思,恰好今天有空,顺便整理了一下这些知识点. 问题描述:下面SQL,创建一个超过255列的表(实际为 ...