The trouble of Xiaoqian
来源:互联网 发布:java 从url去掉ip地址 编辑:程序博客网 时间:2024/06/07 07:16
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 longusing 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
- HDU3591-The trouble of Xiaoqian
- The trouble of Xiaoqian HDU
- The trouble of Xiaoqian(混合背包)
- 【HDU 3591】The trouble of Xiaoqian
- hdu 3591 The trouble of Xiaoqian(多重背包+完全背包)
- hdu 3591 The trouble of Xiaoqian ( 多重背包 + 完全背包 )
- HDU3591 - The trouble of Xiaoqian(多重背包+完全背包)
- hdu 3591 The trouble of Xiaoqian 多重背包+完全背包
- HDU 3591 The trouble of Xiaoqian(多重背包+完全背包)
- hdu 3591 The trouble of Xiaoqian 多重背包+完全背包。。。
- HDU 3591 The trouble of Xiaoqian (多重背包+完全背包)
- hdu 3591The trouble of Xiaoqian (多重背包)
- hdu3591 The trouble of Xiaoqian(多重背包问题)
- hdu 3591 The trouble of Xiaoqian(多重背包)
- hdu3591 The trouble of Xiaoqian(多重背包 + 完全背包)
- HDU3591:The trouble of Xiaoqian(多重背包+完全背包)
- hdu3591The trouble of Xiaoqian(多重背包)
- 常见26个jquery使用技巧详解(比如禁止右键点击、隐藏文本框文字等)
- cocos自定义类 绑定到lua
- 消除jquery Mobile自动添加的样式
- 从贝叶斯理论到图像马尔科夫随机场
- GXDialog 使用方法
- The trouble of Xiaoqian
- 关于 Core Location 的笔记
- 我为什么维护这个关于技术的博客
- 为什么程序员的业余项目大多都死了?
- 阻尼滑动--可以滑动过度的ScrollView(OverScrollView)
- 漫话C++0x
- 汽车4S店经验指标完成情况报表制作分享
- java简易图书管理之三层模式
- 计算字符匹配相似度