The trouble of Xiaoqian

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 1472 Accepted Submission(s): 502

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

背包比较好的题,对于xiaoqian想要使经手的钱做少,所以它给店员的钱必定要T<=m<=20000,所以对于xiaoqian进行多重背包,计算付出m时,需要支付钱的数量最小值,对于店员,xiaoqian多给的钱需要找回,找回的钱的数量也要最少,店员的钱是没有限制的所以对店员进行完全背包

最后遍历找最小值

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
#define LL long long
using namespace std; const int INF = 0x3f3f3f3f; const int MAX = 20001; int dp[MAX]; int Dp[MAX]; int w[120]; int c[120]; int MIN; int main()
{
int n,m;
int W=1;
while(scanf("%d %d",&n,&m)&&(n||m))
{
for(int i=0;i<n;i++)
{
scanf("%d",&w[i]);
}
for(int i=0;i<n;i++)
{
scanf("%d",&c[i]);
}
memset(Dp,INF,sizeof(Dp));
memset(dp,INF,sizeof(dp));
Dp[0]=0;
dp[0]=0;
for(int i=0;i<n;i++)
{
int bite=1;
int num=c[i];
while(num)
{
num-=bite;
for(int j=MAX-1;j>=w[i]*bite;j--)
{
Dp[j]=min(Dp[j],Dp[j-w[i]*bite]+bite);
}
if(bite*2<num)
{
bite*=2;
}
else
{
bite=num;
}
}
}
for(int i=0;i<n;i++)
{
for(int j=w[i];j<MAX;j++)
{
dp[j]=min(dp[j],dp[j-w[i]]+1);
}
}
MIN=INF;
for(int i=m;i<MAX;i++)
{
MIN=min(MIN,Dp[i]+dp[i-m]);
}
printf("Case %d: ",W++);
if(MIN==INF)
{
printf("-1\n");
}
else
{
printf("%d\n",MIN);
}
}
return 0;
}

The trouble of Xiaoqian的更多相关文章

  1. hdu 3591 The trouble of Xiaoqian

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

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

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

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

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

  4. HDU 3594 The trouble of Xiaoqian 混合背包问题

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

  5. hdu3591The trouble of Xiaoqian 多重背包+全然背包

    //给出Xiaoqian的钱币的价值和其身上有的每种钱的个数 //商家的每种钱的个数是无穷,xiaoqian一次最多付20000 //问如何付钱交易中钱币的个数最少 //Xiaoqian是多重背包 / ...

  6. HDU - 3591 The trouble of Xiaoqian 题解

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

  7. hdu 3591 多重加完全DP

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

  8. HDU 3591 (完全背包+二进制优化的多重背包)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3591 The trouble of Xiaoqian Time Limit: 2000/1000 M ...

  9. HDU_3591_(多重背包+完全背包)

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

随机推荐

  1. Protostuff序列化

    前言: Java序列化是Java技术体系当中的一个重要议题,序列化的意义在于信息的交换和存储,通常会和io.持久化.rmi技术有关(eg:一些orm框架会要求持久化的对象类型实现Serializabl ...

  2. PostgreSQL Replication之第十一章 使用Skytools(2)

    11.2 剖析 skytools Skytools 不只是一个单一的脚本,而是一个提供各种不同服务的工具的集合.一旦我们安装了Skytools,更详细地查一下这些组件的细节是有意义的: • londi ...

  3. SpringMVC注解@RequestParam全面解析

    在SpringMVC后台控制层获取参数的方式主要有两种,一种是request.getParameter("name"),另外一种是用注解@RequestParam直接获取.这里主要 ...

  4. SQL in查询

    --sal为员工工资 select * from emp;

  5. TImageList 和 TlistView 组件(C++Builder)

    __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { //加载图标到Imagelist Graphics::TBitmap *bm ...

  6. CentOS 7 下引导 Windows7 启动

    Win7/CentOS7 u盘安装后会覆盖硬盘上已有系统的’引导‘ CentOS7下恢复Win7引导 编辑 # vim /etc/grub.d/40_custom 添加 menuentry 'Wind ...

  7. [转]SecureCRT使用配置详细图文教程

        Secure CRT是一款支持 SSH2.SSH1.Telnet.Telnet/SSH.Relogin.Serial.TAPI.RAW 等协议的终端仿真程序,最吸引我的是,SecureCRT ...

  8. UML: 活动图

    摘自http://www.umlonline.org/school/thread-36-1-1.html 活动图和流程图很类似,我们看看一个流程图的例子: 活动图是用来描述流程的一种图,它与流程图的不 ...

  9. C++新手之详细介绍MFC

     MFC (Microsoft Foundation Class Library)中的各种类结合起来构成了一个应用程序框架,它的目的就是让程序员在此基础上来建立Windows下的应用程序,这是一种相对 ...

  10. HDU 4718 The LCIS on the Tree(树链剖分)

    Problem Description For a sequence S1, S2, ... , SN, and a pair of integers (i, j), if 1 <= i < ...