题目网址: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…
题意:略 多重背包 #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://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…
Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 30006   Accepted: 10811 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…
链接:POJ - 1276 题意:给你一个最大金额m,现在有n种类型的纸票,这些纸票的个数各不相同,问能够用这些纸票再不超过m的前提下凑成最大的金额是多少? 题解:写了01背包直接暴力,结果T了,时间复杂度太高了,要跑外循环m和内循环所有的纸票的个数.这个题需要把每种纸票的的个数存的时候转化成2的次幂的形式来存,比如有8个$1,就可以存成1,2,4,1.这样就可以不存放8个1了,如果在个数大的情况下存储的也不会很多,因为转化成这样子,在1~8每一个都可以凑出来,随机搭配,另一方面,如果是8个$2…
http://poj.org/problem?id=1276 #include <stdio.h> #include <string.h> ; #define Max(a,b) (a)>(b)?(a):(b) int dp[N],cash; void ZeroOnePack(int cost)//01背包 { for (int i = cash; i >= cost; i--) { dp[i] = Max(dp[i],dp[i-cost]+cost); } } void…
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24213 Accepted: 8476 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 machin…
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…
题目:http://poj.org/problem?id=1276 多重背包模板题,没什么好说的,但是必须利用二进制的思想来求,否则会超时,二进制的思想在之前的博客了有介绍,在这里就不多说了. #include <iostream> #include <string.h> #include <stdio.h> #include <algorithm> #include <math.h> using namespace std; ],cnt[],d…
题目http://poj.org/problem?id=1276 分析 这是一个多重背包的问题,可以把请求的金额当作背包的重量,而货币的面值就是价值又是重量. 于是这个问题便很好理解背包了. #];;  ;  }  ZeroOnePack(amount],d[]; ;i,;i;}   来自为知笔记(Wiz)…
题目大意 给定一个容量为M的背包以及n种物品,每种物品有一个体积和数量,要求你用这些物品尽量的装满背包 题解 就是多重背包~~~~用二进制优化了一下,就是把每种物品的数量cnt拆成由几个数组成,1,2,4,~~~cnt-2^K+1,k满足cnt-2^K+1>0的最大整数,体积和价值乘上相应的数就是相应物品的价值和体积,这样用这些物品能够表示1~~cnt所有的情况~~~这就转化成01背包了~~~ 代码: #include <iostream> #include <cstdio>…
多重背包的模型,但一开始直接将N个物品一个一个拆,拆成01背包竟然T了!!好吧OI过后多久没看过背包问题了,翻出背包九讲看下才发现还有二进制优化一说........就是将n个物品拆成系数:1,2,4,8....*物品价值和空间的物品,在这题中只要乘上money[i]就行了,从二进制考虑发现,这样可以组成0~n中所有的数 #include <iostream> #include <cstdio> #include<string.h> using namespace std…
题目链接:https://cn.vjudge.net/problem/POJ-1276 题意 懒得写了自己去看好了,困了赶紧写完这个回宿舍睡觉,明早还要考试. 思路 多重背包的二进制优化. 思路是将n个物品拆分成log(m)个物品,可使得这些物品组合出1~n个原物品,这个用于01背包中. 提交过程 WA 没理解num-=k AC 代码 #include <cstdio> #include <cstring> #include <algorithm> using name…
题意:直接说数据,735是目标值,然后3是后面有三种钱币,四张125的,六张五块的和三张350的. 思路:能够轻易的看出这是一个多重背包问题,735是背包的容量,那些钱币是物品,而且有一定的数量,是多种背包.但是做的时候总是超时.可能是因为m和n太大.然后可以通过二进制把它转化为01背包,因为将钱币的数量化为二进制,1   2    4直到数量减一.化成的二进制数字排列组合,可以组成任意钱币数量内的数字. 看代码: //二进制优化 多重背包转化为01背包 #include<stdio.h> i…
Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44409   Accepted: 16184 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 e…
题目地址:http://poj.org/problem?id=1276 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…
<span style="color:#000099;">/* Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26604 Accepted: 9397 Description A Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bi…
Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 32971   Accepted: 11950 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…
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…
http://poj.org/problem?id=1742 n个硬币,面值分别是A1...An,对应的数量分别是C1....Cn.用这些硬币组合起来能得到多少种面值不超过m的方案. 多重背包,不过这题很容易超时,用背包九讲的代码有人说行,但是我提交还是超时,后来参考别人代码加了一些优化才能过,有时间要去搞清楚多重背包的单调队列优化. #include<cstdio> #include<cstring> #include<algorithm> using namespa…
http://poj.org/problem?id=1014 题意:6个物品,每个物品都有其价值和数量,判断是否能价值平分. 思路: 多重背包.利用二进制来转化成0-1背包求解. #include<iostream> #include<string> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; ; int sum; ]; int d[max…
Dividing   Description Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same value, because then they cou…
Coins Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 25827 Accepted: 8741 Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar.One day Tony opened his money-box and found there were some coin…
题意:有n种面额的硬币.面额.个数分别为A_i.C_i,求最多能搭配出几种不超过m的金额? 思路:dp[j]就是总数为j的价值是否已经有了这种方法,如果现在没有,那么我们就一个个硬币去尝试直到有,这种价值方法有了的话,那么就是总方法数加1.多重背包可行性问题 传统多重背包三重循环会超时,因为只考虑是否可行,没有考虑剩余面额数量的因素. o(n*v)方法 #include <iostream> #include <cstdio> #include <string.h> #…
一.Description People in Silverland use coins.They have coins of value A1,A2,A3...An Silverland dollar.One day Tony opened his money-box and found there were some coins.He decided to buy a very nice watch in a nearby shop. He wanted to pay the exact p…
<挑战程序设计竞赛>上DP的一道习题. 很裸的多重背包.下面对比一下方法,倍增,优化定义,单调队列. 一开始我写的倍增,把C[i]分解成小于C[i]的2^x和一个余数r. dp[i][j]的定义前i个数字能否到凑出j来,改成一位滚动数组. #include<cstdio> #include<iostream> #include<string> #include<cstring> #include<queue> #include<…