Coins

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11596    Accepted Submission(s): 4634

Problem Description
Whuacmers 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.

 
Input
The 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.
 
Output
For each test case output the answer on a single line.
 
Sample Input
3 10
1 2 4 2 1 1
2 5
1 4 2 1
0 0
 
Sample Output
8
4
 
Source
 
 
题意:有不同面值的 相应数量不同n种硬币  问1~m元的价格有哪些 可以由硬币组成 f[i]==i
 
题解: 多重背包    二进制优化
 #include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<queue>
#include<stack>
using namespace std;
int n,m;
struct node
{
int a,c;
} N[];
int f[];
int ans;
int value[],size[];
int count;
void slove(int q)
{
count=;
for(int i=;i<=q;i++)
{
int c=N[i].c,v=N[i].a;
for (int k=; k<=c; k<<=)
{
value[count] = k*v;
size[count++] = k*v;
c -= k;
}
if (c > )
{
value[count] = c*v;
size[count++] = c*v;
}
}
}
int main()
{
while(scanf("%d %d",&n,&m)!=EOF)
{
if(n==&&m==)
break;
for(int i=; i <= m; i++)
f[i] = ;
ans=;
for(int i=;i<=n;i++)
scanf("%d",&N[i].a);
for(int i=;i<=n;i++)
scanf("%d",&N[i].c);
slove(n);
for(int i=;i<count;i++)
for(int gg=m;gg>=size[i];gg--)
f[gg]=max(f[gg],f[gg-size[i]]+value[i]);
for(int i=;i<=m;i++)
if(f[i]==i)
ans++;
cout<<ans<<endl;
}
return ;
}
 

HDU 2844 二进制优化的多重背包的更多相关文章

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

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

  2. HDU 3732 Ahui Writes Word(多重背包)

    HDU 3732 Ahui Writes Word(多重背包) http://acm.hdu.edu.cn/showproblem.php? pid=3732 题意: 初始有N个物品, 每一个物品有c ...

  3. HDU 5445 Food Problem(多重背包+二进制优化)

    http://acm.hdu.edu.cn/showproblem.php?pid=5445 题意:现在你要为运动会提供食物,总共需要提供P能量的食物,现在有n种食物,每种食物能提供 t 能量,体积为 ...

  4. 多重背包!!!(二进制优化的01背包)hdoj-2844

    #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...

  5. HDU 3732 Ahui Writes Word 多重背包优化01背包

    题目大意:有n个单词,m的耐心,每个单词有一定的价值,以及学习这个单词所消耗的耐心,耐心消耗完则,无法学习.问能学到的单词的最大价值为多少. 题目思路:很明显的01背包,但如果按常规的方法解决时间复杂 ...

  6. HDU 2082 找单词 (多重背包)

    题意:假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26.那么,对于给定的字母,可以找到多少价值<=50的 ...

  7. HDU 1059 Dividing 分配(多重背包,母函数)

    题意: 两个人共同收藏了一些石头,现在要分道扬镳,得分资产了,石头具有不同的收藏价值,分别为1.2.3.4.5.6共6个价钱.问:是否能公平分配? 输入: 每行为一个测试例子,每行包括6个数字,分别对 ...

  8. HDU 5445——Food Problem——————【多重背包】

    Food Problem Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)To ...

  9. ACM学习历程—HDU 1059 Dividing(dp && 多重背包)

    Description Marsha and Bill own a collection of marbles. They want to split the collection among the ...

随机推荐

  1. 51定时器控制4各led,使用回调函数机制

    程序转载自51hei,经过自己的实际验证,多了一种编程的思路技能,回调函数的基本思想也是基于事件机制的,哪个事件来了, 就执行哪个事件. 程序中,最多四个子定时器,说明51的处理速度是不够的,在中断中 ...

  2. Waterline从概念到实操

    Waterline基本介绍 Waterline是什么 Waterline是下一代存储和检索引擎,也是Sails框架中使用的默认ORM . ORM的基本概念 Object Relational Mapp ...

  3. 初步学习pg_control文件之二

    接前文:初步认识pg_control文件 继续学习,pg_control文件在何处形成的?是在initdb的时候,运用的函数如下: /* * This func must be called ONCE ...

  4. linux shell中读写操作mysql数据库

    本文介绍了如何在shell中读写mysql数据库.主要介绍了如何在shell 中连接mysql数据库,如何在shell中创建数据库,创建表,插入csv文件,读取mysql数据库,导出mysql数据库为 ...

  5. jmeter插件之jsonpath提取响应结果和做断言

    准备工作: 1. jmeter3.X已经自带了提取响应结果的插件:JSON Extractor 2. 下载断言插件:https://jmeter-plugins.org/wiki/JSONPathAs ...

  6. CSS里一个奇怪的属性

    事情是这样的,在一个手机界面的制作中,我发现按钮点击后总会出现一个边框,于是开始搜索解决方案.搜到的解决方案是这样的. a:focus,input:focus{ -webkit-tap-highlig ...

  7. 分分钟搞定redis

    随着科技不断的发展,使用到的技术也是更新换代,大家都知道当一个程序用户量上来之后,必然是要做数据缓存的,那么如何去实现的呢,在之前我们一直使用memcache去做数据缓存,现在众所周知主流的缓存技术已 ...

  8. java 泛型类转型

    public class NeedCasting { @SuppressWarnings("unchecked") public void f(String[] args)thro ...

  9. Spring框架中ModelAndView、Model、ModelMap的区别

    转自:http://blog.csdn.net/liujiakunit/article/details/51733211 1. Model Model 是一个接口, 其实现类为ExtendedMode ...

  10. 在 C/C++ 中使用 TensorFlow 预训练好的模型—— 间接调用 Python 实现

    现在的深度学习框架一般都是基于 Python 来实现,构建.训练.保存和调用模型都可以很容易地在 Python 下完成.但有时候,我们在实际应用这些模型的时候可能需要在其他编程语言下进行,本文将通过 ...