The trouble of Xiaoqian

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2166    Accepted Submission(s): 773

Problem Description
In
the country of ALPC , Xiaoqian is a very famous mathematician. She is
immersed in calculate, and she want to use the minimum number of coins
in every shopping. (The numbers of the shopping include the coins she
gave the store and the store backed to her.)
And now , Xiaoqian wants
to buy T (1 ≤ T ≤ 10,000) cents of supplies. The currency system has N
(1 ≤ N ≤ 100) different coins, with values V1, V2, ..., VN (1 ≤ Vi ≤
120). Xiaoqian is carrying C1 coins of value V1, C2 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 .But Xiaoqian is a low-pitched girl , she wouldn’t like
giving out more than 20000 once.
 
Input
There are several test cases in the input.
Line 1: Two space-separated integers: N and T.
Line 2: N space-separated integers, respectively V1, V2, ..., VN coins (V1, ...VN)
Line 3: N space-separated integers, respectively C1, C2, ..., CN
The end of the input is a double 0.
 
Output
Output
one line for each test case like this ”Case X: Y” : X presents the Xth
test case and Y presents the minimum number of coins . If it is
impossible to pay and receive exact change, output -1.
 
Sample Input
3 70
5 25 50
5 2 1
0 0
 
Sample Output
Case 1: 3
此题为多重背包和完全背包的混合,可分开求,在求最小值
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll dpf[],dps[];
ll a[],b;
ll ans,pos,n,m;
int main()
{
int count=;
while(scanf("%lld%lld",&n,&m) && n+m)
{
for(int i=;i<;i++)
{
dps[i]=dpf[i]=INF;
}
dps[]=dpf[]=;
for(int i=;i<n;i++)
{
scanf("%lld",&a[i]);
}
for(int i=;i<n;i++)
{
scanf("%lld",&b);
for(int k=;b;k*=)
{
if(b<k) k=b;
for(int j=;j>=k*a[i];j--)
{
dpf[j]=min(dpf[j],dpf[j-k*a[i]]+k);
}
b-=k;
}
}
for(int i=;i<n;i++)
{
for(int j=a[i];j<=;j++)
{
dps[j]=min(dps[j],dps[j-a[i]]+);
}
}
ans=INF;
for(int i=m;i<=;i++)
{
ans=min(ans,dpf[i]+dps[i-m]);
}
if(ans==INF) ans=-;
printf("Case %d: %lld\n",count++,ans);
}
return ;
}

HDU 3594 The trouble of Xiaoqian 混合背包问题的更多相关文章

  1. HDU 3591 The trouble of Xiaoqian(多重背包+全然背包)

    HDU 3591 The trouble of Xiaoqian(多重背包+全然背包) pid=3591">http://acm.hdu.edu.cn/showproblem.php? ...

  2. hdu 3591 The trouble of Xiaoqian

    hdu 3591  The trouble of Xiaoqian 题意:xiaoqi要买一个T元的东西,当前的货币有N种,xiaoqi对于每种货币有Ci个:题中定义了最小数量即xiaoqi拿去买东西 ...

  3. HDU - 3591 The trouble of Xiaoqian 题解

    题目大意 有 \(N\) 种不同面值的硬币,分别给出每种硬币的面值 \(v_i\) 和数量 \(c_i\).同时,售货员每种硬币数量都是无限的,用来找零. 要买价格为 \(T\) 的商品,求在交易中最 ...

  4. The trouble of Xiaoqian

    The trouble of Xiaoqian Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...

  5. HDUOJ-----3591The trouble of Xiaoqian

    The trouble of Xiaoqian Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  6. HDU 3594.Cactus 仙人掌图

    Cactus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  7. HDU 2602 Bone Collector(经典01背包问题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/O ...

  8. HDU 3594 Cactus(仙人掌问题)

    http://acm.hdu.edu.cn/showproblem.php?pid=3594 题意: 一个有向图,判断是否强连通和每条边只在一个环中. 思路: 仙人掌问题. 用Tarjan算法判断强连 ...

  9. hdu - 3594 Cactus (强连通)

    http://acm.hdu.edu.cn/showproblem.php?pid=3594 判断给定的图是否是强连通的,并且每条边都只属于一个连通分量. 判断强连通只需要判断缩点之后顶点数是否为1即 ...

随机推荐

  1. 24 款必备的 Linux 桌面应用(2016 版)

    作者: Munif Tanjim 译者: LCTT GHLandy | 2016-12-21 08:41   评论: 41 收藏: 13 摘要:Linux 的必备软件有哪些?这将会是一个非常主观的回答 ...

  2. 阿里云slb上传证书错误

    阿里云上传证书错误 今天在阿里云给slb上传新买的证书,传的过程中报错了,如下: 网上找了半天没找到,鼠标放在错误哪行行首,会报一个错 大意就是一行最多64个字符,我检查了下,报错这行是68个字符,于 ...

  3. [SDOI2011]消防(树的直径)

    [SDOI2011]消防 题目描述 某个国家有n个城市,这n个城市中任意两个都连通且有唯一一条路径,每条连通两个城市的道路的长度为zi(zi<=1000). 这个国家的人对火焰有超越宇宙的热情, ...

  4. javascript与DOM节点的结合使用

    文档对象模型(Document Object Model,简称DOM),是W3C组织推荐的处理可扩展标志语言的标准编程接口.在网页上,组织页面(或文档)的对象被组织在一个树形结构中,用来表示文档中对象 ...

  5. 08-for循环

  6. 【Codeforces Round #462 (Div. 1) B】A Determined Cleanup

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 设\(设f(x)=a_d*x^{d}+a_{d-1}*x^{d-1}+...+a_1*x+a_0\) 用它去除x+k 用多项式除法除 ...

  7. HBase为什么快 HBase原理。 HBase几个问题

    背景色表示可以自己做实验搞定 1 模拟一组数据 1.2.3.4.5.6.7.8.9.10     1 入 限定符 'one'     2 入 'two'     3 入 'three'     4 f ...

  8. ORA-12514: TNS: 监听程序当前无法识别连接描写叙述符中请求的服务

    不指定数据库能够正常连接: 指定数据库和使用PL/SQL Developer都出现错误: 在此说明一下我的环境:Oralce装的是64位的在使用PL/SQL Developer时曾出现过初始化错误,解 ...

  9. OpenGL编程逐步深入(二)在窗口中显示一个点

    准备知识 在本文中我们将会接触到OpenGl的扩展库GLEW( OpenGL Extension Wrangler Library),GLEW可以帮助我们处理OpenGl中繁琐的扩展管理.一旦初始化后 ...

  10. Oracle 删除重复数据的几种方法

    去重 第一种:distinct create table tmp_t3 as select distinct * from t3; drop table t3; alter table tmp_t2 ...