Coins

Time Limit: / MS (Java/Others)    Memory Limit: / K (Java/Others)
Total Submission(s): Accepted Submission(s): 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( ≤ n ≤ ),m(m ≤ ).The second line contains 2n integers, denoting A1,A2,A3...An,C1,C2,C3...Cn ( ≤ Ai ≤ , ≤ Ci ≤ ). The last test case is followed by two zeros. Output
For each test case output the answer on a single line. Sample Input Sample Output Source
Multi-University Training Contest - Host by WHU // 多重背包 二进制优化
#include <iostream>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;
int
M[];
int
main()
{

int
A[],C[];
int
n,m;
int
i,j,k;
while
(scanf("%d %d",&n,&m),n|m){
for
(i=;i<=n;i++)
scanf("%d",&A[i]);
for
(i=;i<=n;i++)
scanf("%d",&C[i]);
M[]=;
for
(i=;i<=m;i++)
M[i]=;
int
temp;
for
(i=;i<=n;i++){
k=;
while
(k<=C[i]){
C[i]-=k;
temp=k*A[i];
for
(j=m;j>=temp;j--)
if
(M[j-temp])
M[j]=;
k=k<<;
}

if
(C[i]>) {k=C[i];
temp=k*A[i];
for
(j=m;j>=temp;j--)
if
(M[j-temp])
M[j]=;
}
}

k=;
for
(i=;i<=m;i++)
if
(M[i])k++;
printf("%d\n",k);
}

return
;
}

hdu 2844 Coins的更多相关文章

  1. HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)

    HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...

  2. 背包系列练习及总结(hud 2602 && hdu 2844 Coins && hdu 2159 && poj 1170 Shopping Offers && hdu 3092 Least common multiple && poj 1015 Jury Compromise)

    作为一个oier,以及大学acm党背包是必不可少的一部分.好久没做背包类动规了.久违地练习下-.- dd__engi的背包九讲:http://love-oriented.com/pack/ 鸣谢htt ...

  3. HDU 2844 Coins (多重背包计数 空间换时间)

    Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  4. hdu 2844 Coins (多重背包)

    题意是给你几个数,再给你这几个数的可以用的个数,然后随机找几个数来累加, 让我算可以累加得到的数的种数! 解题思路:先将背包初始化为-1,再用多重背包计算,最后检索,若bb[i]==i,则说明i这个数 ...

  5. POJ 1742 hdu 2844 Coins

    题目链接:http://poj.org/problem?id=1742 http://acm.hdu.edu.cn/showproblem.php?pid=2844 题目分类:动态规划 代码: #in ...

  6. hdu 2844 Coins (多重背包+二进制优化)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2844 思路:多重背包 , dp[i] ,容量为i的背包最多能凑到多少容量,如果dp[i] = i,那么代表 ...

  7. hdu 2844 coins(多重背包 二进制拆分法)

    Problem Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. On ...

  8. hdu 2844 Coins 多重背包(模板) *

    Coins                                                                             Time Limit: 2000/1 ...

  9. HDU 2844 Coins(多重背包)

    点我看题目 题意 :Whuacmers有n种硬币,分别是面值为A1,A2,.....,An,每一种面值的硬币的数量分别是C1,C2,......,Cn,Whuacmers想买钱包,但是想给人家刚好的钱 ...

随机推荐

  1. MySQL --log-slave-updates

     官方说明:--log-slave-updates Command-Line Format --log-slave-updates Option-File Format log-slave-updat ...

  2. 元类metaClass

    metaClass 实现动态改变对象的能力,这点特别像python(metaClass),Python中类(不是元类)的概念借鉴于Smalltalk groovy demo: class Person ...

  3. 权限管理数据库设计_Rev1

    贴出来自身接触项目以来所接触过的一些企业管理信息系统权限部门的一个通用数据库设计初稿: 设计的文字解释以及各部分的作用等确定可行会再进行描述: 图: 如果有不同意见请轻拍!

  4. Struts 2 Tutorials

    http://www.dzone.com/tutorials/java/struts-2/struts-2-tutorial/struts-2-tutorial.html http://struts. ...

  5. Jquery异步请求简单实例(转)

    本文引用自Xingsoft. 一.Jquery向aspx页面请求数据 前台页面JS代码:             $("#Button1").bind("click&qu ...

  6. java程序练习:x进制转Y进制

    /*X进制到Y进制转换*/ /*Step1.提示用户输入数据的进制X *Step2.接收用户输入的数据,保存到X * Scanner方法 *Step3.接收用户输入X进制的数据,保存到num *Ste ...

  7. 我的vim配置

    之前都在虚拟机下面捣鼓Linux,有种隔靴搔痒的感觉.为了更快地熟悉Linux系统,重新安装了Ubuntu,首先就是配置vim. 下面是我的vim配置,为了方便,我在代码后添加注释说明. 1.配置C/ ...

  8. HDU4631+Set+最近点对

    题意:一个空平面,每次增加一个点, 其坐标根据上一个点算出:(x[i-1] * Ax + Bx ) mod Cx,(y[i-1] * Ay + By ) mod Cy 求出现有点集中的最近点对的距离的 ...

  9. linux 修改命令行编码 乱码解决方案

    修改/etc/default/locale命令:sudo vim /etc/default/locale1将下面这两行 LANG=zh_CN.UTF-8 LANGUAGE=zh_CN:zh 修改为: ...

  10. maven更新总结与tomcat发布方法总结

    这些天来一直为不能直接把项目实时的发布到tomcat而费心思,项目使用了maven来组织,编译和运行,而maven插件的安装曾经有些问题,为此怀疑不能发布项目到tomcat是因为maven有问题,为些 ...