首页 技术 正文
技术 2022年11月10日
0 收藏 765 点赞 4,716 浏览 2102 个字

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 DescriptionIn
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. InputThere 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. OutputOutput
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 Input3 70
5 25 50
5 2 1
0 0 Sample OutputCase 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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,557
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898