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想买钱包,但是想给人家刚好的钱 ...
随机推荐
- onclick控制元素显示与隐藏时,点击第一次无反应的原因
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- 安装Ubuntu时,遇到自定义交换空间swap大小设置问题
【整理】Ubuntu自定义分区设置 在安装Ubuntu时,如果使用的是一个新硬盘那么安装向导会建议你使用整个硬盘,如果硬盘上已经有数据了,向导会建议使用剩余的空间。不管怎样,是由向导自动划分的分区。 ...
- 分享自lordinloft 《[转载]COMPILE_OPT 的用法介绍》
来源:http://blog.sina.com.cn/s/blog_63180b75010117oj.html#bsh-73-372143085
- C#写的SQL聚合函数
SQL Server 字符串连接聚合函数. 注册程序集: 拷贝“SqlStrConcate.dll”至<sql安装根目录>/MSSQL.1/MSSQL/Binn目录下,执行下面的SQL: ...
- UITableViewCell 重合问题解决方法
这两天做ios遇到一个UITableViewCell 数据重合的问题,原因:引起这个问题的主要原因是,重用cell.之前cell上的内容未被清空,而又增加新增内容所致.从网上查了一些解决方法,比如: ...
- EasyUI + EF + MVC4 后台截图
到目前完成的页面截图,完成了增删改查几项功能的技术测试,在解决几个小问题,就重新设计结构开始一个完整的后台开发,坚持用博客和云笔记记录开发过程.
- (转)Const,Const函数,Const变量,函数后面的Const
本文转自http://www.cnblogs.com/Fancyboy2004/archive/2008/12/23/1360810.html 看到const 关键字,C++程序员首先想到的可能是co ...
- Flex 调用webService
今天手头没事,就学习下 Flex 调用webService的方法.本地测试OK 和大家分享下. ——————————————————————————————————————————————————— ...
- PAT-乙级-1030. 完美数列(25)
1030. 完美数列(25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CAO, Peng 给定一个正整数数列,和正整数p,设这 ...
- HDU 1429 胜利大逃亡(续)(三维BFS)
题目链接 题意 : 中文题不详述. 思路 : 这个题和1885差不多一样的,所以我直接改了改那个代码就交上了,链接 #include <stdio.h> #include <stri ...