hdu 2844 Coins
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的更多相关文章
- HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)
HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...
- 背包系列练习及总结(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 ...
- HDU 2844 Coins (多重背包计数 空间换时间)
Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- hdu 2844 Coins (多重背包)
题意是给你几个数,再给你这几个数的可以用的个数,然后随机找几个数来累加, 让我算可以累加得到的数的种数! 解题思路:先将背包初始化为-1,再用多重背包计算,最后检索,若bb[i]==i,则说明i这个数 ...
- POJ 1742 hdu 2844 Coins
题目链接:http://poj.org/problem?id=1742 http://acm.hdu.edu.cn/showproblem.php?pid=2844 题目分类:动态规划 代码: #in ...
- hdu 2844 Coins (多重背包+二进制优化)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2844 思路:多重背包 , dp[i] ,容量为i的背包最多能凑到多少容量,如果dp[i] = i,那么代表 ...
- hdu 2844 coins(多重背包 二进制拆分法)
Problem Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. On ...
- hdu 2844 Coins 多重背包(模板) *
Coins Time Limit: 2000/1 ...
- HDU 2844 Coins(多重背包)
点我看题目 题意 :Whuacmers有n种硬币,分别是面值为A1,A2,.....,An,每一种面值的硬币的数量分别是C1,C2,......,Cn,Whuacmers想买钱包,但是想给人家刚好的钱 ...
随机推荐
- flex打印图片
<?xml version="1.0" encoding="utf-8"?><s:WindowedApplication xmlns:fx=& ...
- svn团队环境
1.安装VisualSVN Server VisualSVN-Server-3.3.1-x64.msi 下载,并安装标准版(免费) 2.下载TortoiseSVN TortoiseSVN-1.8.11 ...
- oracle linux了解基本命令行
1. Linux的版本:核心(kernel)版本和发行(distribution)版本 2. 复制.删除和移动文件的命令 cp [选项] 源文件或目录 目标文件或目录 -R,-r ...
- make问题:make[1] entering directory
执行make distclean命令.
- K2 Blackpearl 4.6.8 安装步骤详解
由于某些原因,我幼小的心灵受到了很大的创伤,倍感世态之炎凉,久久不能愈合,也因此很久没再接触K2 Blackpearl了.偶然来了兴趣,想整个K2的环境,闲暇之余了解其新功能,温故知新,也希望从中能讨 ...
- 【Google Protocol Buffer】Google Protocol Buffer
http://www.ibm.com/developerworks/cn/linux/l-cn-gpb/ Google Protocol Buffer 的使用和原理 Protocol Buffers ...
- EXTJS 4.2 资料 控件之btn设置可否点击
1.下面是一个btn按钮的代码,默认不可以点击 { id: 'skipStep3', disabled: true,//默认不可点击 text: "跳转第三步", handler: ...
- 跨过slf4j和logback,直接晋级log4j 2
今年一直关注log4j 2,但至今还没有出正式版.等不及了,今天正式向大家介绍一下log4j的升级框架,log4j 2. log4j,相信大家都熟悉,至今对java影响最大的logging系统,至今仍 ...
- PHP 5.3连接sql server 2008 R2
我的机器为: xp sp3 sql server 2008 developer apache 2.2.2 php 5.3 从5.3开始,php就不再提供mssql.dll了,所以要php连接sql ...
- js 全选 反选
1.全选 function selectAll(form){ for (var i = 0; i < form.elements.length; i++) { if (form.elements ...