The trouble of Xiaoqian
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的更多相关文章
- hdu 3591 The trouble of Xiaoqian
hdu 3591 The trouble of Xiaoqian 题意:xiaoqi要买一个T元的东西,当前的货币有N种,xiaoqi对于每种货币有Ci个:题中定义了最小数量即xiaoqi拿去买东西 ...
- HDUOJ-----3591The trouble of Xiaoqian
The trouble of Xiaoqian Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- HDU 3591 The trouble of Xiaoqian(多重背包+全然背包)
HDU 3591 The trouble of Xiaoqian(多重背包+全然背包) pid=3591">http://acm.hdu.edu.cn/showproblem.php? ...
- HDU 3594 The trouble of Xiaoqian 混合背包问题
The trouble of Xiaoqian Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- hdu3591The trouble of Xiaoqian 多重背包+全然背包
//给出Xiaoqian的钱币的价值和其身上有的每种钱的个数 //商家的每种钱的个数是无穷,xiaoqian一次最多付20000 //问如何付钱交易中钱币的个数最少 //Xiaoqian是多重背包 / ...
- HDU - 3591 The trouble of Xiaoqian 题解
题目大意 有 \(N\) 种不同面值的硬币,分别给出每种硬币的面值 \(v_i\) 和数量 \(c_i\).同时,售货员每种硬币数量都是无限的,用来找零. 要买价格为 \(T\) 的商品,求在交易中最 ...
- hdu 3591 多重加完全DP
题目: The trouble of Xiaoqian Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- HDU 3591 (完全背包+二进制优化的多重背包)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3591 The trouble of Xiaoqian Time Limit: 2000/1000 M ...
- HDU_3591_(多重背包+完全背包)
The trouble of Xiaoqian Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
随机推荐
- 从零开始PHP攻略(3)——数据的存储与检索
要点目录: I.保存数据 II.打开文件 III.创建并写入文件 IV.关闭文件 V.读文件 VI.给文件加锁 VII.删除文件 VIII.其他有用的文件操作函数 IX.数据库管理系统 1.保存数 ...
- Lintcode: Wood Cut
Given n pieces of wood with length L[i] (integer array). Cut them into small pieces to guarantee you ...
- Leetcode: Palindrome Numbers
Determine whether an integer is a palindrome. Do this without extra space. 尝试用两头分别比较的方法,结果发现无法解决1000 ...
- 一个新人对JavaScript的内容简单介绍
JavaScript 1.基本的数据类型:字符串 小数 整数 时间日期 布尔型等. 2.变量: JS定义变量通通都是用var开头,var里面可以放任何东西(如:小数,整数,字符串,时间日期等等 ...
- java 读取Excel文件并数据持久化方法Demo
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util ...
- FAQ: C++中定义类的对象:用new和不用new有何区别?
C++用new创建对象和不用new创建对象的区别解析 作者: 字体:[增加 减小] 类型:转载 时间:2013-07-26 我要评论 在C++用new创建对象和不用new创建对象是有区别的,不知你是否 ...
- poj 1731 Orders
http://poj.org/problem?id=1731 Orders Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9 ...
- [转]gitHub客户端Desktop的安装使用总结 ---基础篇
gitHub客户端Desktop的安装使用总结 ---基础篇 发表于2015/12/11 11:41:57 8399人阅读 分类: Android之应用实战 这段时间想把我写的东西上传到github ...
- [原创] hadoop学习笔记:hadoopWEB监控
笔者安装单机版本 要想实现hadoopweb页面的监控,需要解决以下几个问题 1.关闭linux的防火墙:#service iptables stop 2.将linuxSE设置为disabled:#v ...
- 1019: A+B和C比大小
1019: A+B和C比大小 时间限制: 1 Sec 内存限制: 128 MB提交: 518 解决: 300[提交][状态][讨论版] 题目描述 给定区间[-231, 231]内的3个整数A.B和 ...