首页 技术 正文
技术 2022年11月10日
0 收藏 698 点赞 2,744 浏览 1766 个字

Coins

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

Problem DescriptionWhuacmers use coins.They have coins of value A1,A2,A3…An Silverland dollar. One day Hibix opened purse and found there were some coins. He decided to buy a very nice watch in a nearby shop. He wanted to pay the exact price(without change) and he known the price would not more than m.But he didn’t know the exact price of the watch.

You are to write a program which reads n,m,A1,A2,A3…An and C1,C2,C3…Cn corresponding to the number of Tony’s coins of value A1,A2,A3…An then calculate how many prices(form 1 to m) Tony can pay use these coins.

 InputThe input contains several test cases. The first line of each test case contains two integers n(1 ≤ n ≤ 100),m(m ≤ 100000).The second line contains 2n integers, denoting A1,A2,A3…An,C1,C2,C3…Cn (1 ≤ Ai ≤ 100000,1 ≤ Ci ≤ 1000). The last test case is followed by two zeros. OutputFor each test case output the answer on a single line. Sample Input3 101 2 4 2 1 12 51 4 2 10 0 Sample Output84 

#include<iostream>
#include<cmath>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
typedef long long ll;
#define INF 0x3f3f3f3f
using namespace std;
#define maxn 100005
int a[maxn],c[maxn],dp[maxn];
int main(){
int n,m;
while(cin >> n >> m){
if(!n && !m){
break;
}
for(int i=;i<n;i++){
cin >> a[i];//a[i]既是物体的体积,又是物体的价值
}
for(int i=;i<n;i++){
cin >> c[i]; //c[i]是物体的数量
}
memset(dp,,sizeof(dp));
for(int i=;i<n;i++){
if(a[i]*c[i]>=m){//体积乘以数量大于总体积,说明不能完全装完,相当于有无穷件,用完全背包
for(int j=a[i];j<=m;j++){
dp[j] = max(dp[j],dp[j-a[i]]+a[i]);
}
}
else{//可以装完,用01背包
int k = ;
while(k<c[i]){//二进制优化
for(int j=m;j>=a[i]*k;j--){
dp[j] = max(dp[j],dp[j-a[i]*k]+a[i]*k);
}
c[i] -= k;
k *= ;
}
for(int j=m;j>=a[i]*c[i];j--){
dp[j] = max(dp[j],dp[j-a[i]*c[i]]+a[i]*c[i]);
}
}
}
int count = ;//计数
for(int i=;i<=m;i++){
if(dp[i] == i){
count++;//可以组合且不用找钱
}
}
cout << count << endl;
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,965
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,486
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,331
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,114
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,747
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,781