poj 1276 Cash Machine_多重背包】的更多相关文章

题意:略 多重背包 #include <iostream> #include<cstring> #include<cstdio> using namespace std; #define MAXV 15 #define MAXM 100050 int cash,n,value[MAXV],c[MAXV],f[MAXM],user[MAXM]; int main(){ int i,j,max; while(~scanf("%d%d",&cash…
题目网址:http://poj.org/problem?id=1276 思路: 很明显是多重背包,把总金额看作是背包的容量. 刚开始是想把单个金额当做一个物品,用三层循环来 转换成01背包来做.T了…… 后面学习了 用二进制来处理数据. 简单地介绍一下二进制优化:✧(≖ ◡ ≖✿)  假设数量是8,则可以把它看成是1,2,4,1的组合,即这4个数的组合包括了1-8的所有取值情况.这是为什么呢?将它们转换成二进制再观察一下: 1:1 2:10 4:100 1:1 二进制都只有0,1.所以1,2,4…
Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26172   Accepted: 9238 Description A Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bills for a requested cash amount. The ma…
Description A Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bills for a requested cash amount. The machine uses exactly N distinct bill denominations, say Dk, k=1,N, and for each denomination Dk the…
链接:POJ - 1276 题意:给你一个最大金额m,现在有n种类型的纸票,这些纸票的个数各不相同,问能够用这些纸票再不超过m的前提下凑成最大的金额是多少? 题解:写了01背包直接暴力,结果T了,时间复杂度太高了,要跑外循环m和内循环所有的纸票的个数.这个题需要把每种纸票的的个数存的时候转化成2的次幂的形式来存,比如有8个$1,就可以存成1,2,4,1.这样就可以不存放8个1了,如果在个数大的情况下存储的也不会很多,因为转化成这样子,在1~8每一个都可以凑出来,随机搭配,另一方面,如果是8个$2…
Description A Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bills for a requested cash amount. The machine uses exactly N distinct bill denominations, say Dk, k=1,N, and for each denomination Dk the…
题意:直接说数据,735是目标值,然后3是后面有三种钱币,四张125的,六张五块的和三张350的. 思路:能够轻易的看出这是一个多重背包问题,735是背包的容量,那些钱币是物品,而且有一定的数量,是多种背包.但是做的时候总是超时.可能是因为m和n太大.然后可以通过二进制把它转化为01背包,因为将钱币的数量化为二进制,1   2    4直到数量减一.化成的二进制数字排列组合,可以组成任意钱币数量内的数字. 看代码: //二进制优化 多重背包转化为01背包 #include<stdio.h> i…
转载地址:http://m.blog.csdn.net/blog/u010489766/9229011 题目链接:http://poj.org/problem?id=1276 题意:机器里面共有n种面额的钱币,每种各ni张,求机器吐出小于等于所要求钱币的最大值 解析1:这题大牛都用了多重背包,不过,我一同学想出了一种就这题而言特别简单有效的方 法.(话说我就认为这题本来就不需要用到背包的,因为n的范围只到10,太小了).方法就是对钱进行遍历,看这些钱一共能组成多少面额的钱,然后从 cash向下枚…
Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 33444   Accepted: 12106 Description A Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bills for a requested cash amount. The m…
Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 38986   Accepted: 14186 Description A Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bills for a requested cash amount. The m…