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. js数组的操作 Full

    js数组的操作 用 js有很久了,但都没有深究过js的数组形式.偶尔用用也就是简单的string.split(char).这段时间做的一个项目,用到数组的地方很多,自以为js高手的自己居然无从下手,一 ...

  2. Chromium Graphics: Graphics and Skia

    Graphics and Skia Chrome uses Skia for nearly all graphics operations, including text rendering. GDI ...

  3. Linux 下易用的光盘镜像管理工具(虚拟光驱软件)转载

    作者: Frazer Kline | 2014-11-23 11:07   评论: 4 收藏: 4 分享: 10 磁盘镜像包括了整个磁盘卷的文件或者是全部的存储设备的数据,比如说硬盘,光盘(DVD,C ...

  4. HTML5的核心内容

    开发者可以放心地使用html5的理由 兼容性.HTML5在老版本的浏览器可以正常运行,同时支持HTML5的新浏览器也能正常运行HTML4,用HTML4创建出来的网站不是必须全部重建的. 实用性.HTM ...

  5. python 异步IO-aiohttp与简单的异步HTTP客户端/服务器

    参考链接:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/00143209814 ...

  6. Spring Cloud学习笔记【六】Hystrix 监控数据聚合 Turbine

    上一篇我们介绍了使用 Hystrix Dashboard 来展示 Hystrix 用于熔断的各项度量指标.通过 Hystrix Dashboard,我们可以方便的查看服务实例的综合情况,比如:服务调用 ...

  7. codevs——T1337 银行里的迷宫

     时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver 题解       题目描述 Description 楚楚每一次都在你的帮助下过了一关又一关(比如他开宴会). ...

  8. 跨域post 及 使用token防止csrf 攻击

    环境: 后台使用的python - flask 前台使用angular框架 1.一个跨域post的样例: 跨域post有多种实现方式: 1.CORS:http://blog.csdn.net/hfah ...

  9. CSS元素选择器 element selector(type selector)

    http://www.w3school.com.cn/css/css_selector_type.asp 元素选择器 最常见的 CSS 选择器是元素选择器.换句话说,文档的元素就是最基本的选择器. 如 ...

  10. MySQL自定义函数(四十六)

    MySQL自定义函数 一.什么是MYSQL自定义函数? mysql当中的自定义函数,我们简称为UDF,它实际上是一种对MySQL扩展的途径,其用法与内置函数相同. 二.自定义函数应该具备哪些条件? 我 ...