POJ1276 - Cash Machine(多重背包)】的更多相关文章

题目链接: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…
题目大意 给定一个容量为M的背包以及n种物品,每种物品有一个体积和数量,要求你用这些物品尽量的装满背包 题解 就是多重背包~~~~用二进制优化了一下,就是把每种物品的数量cnt拆成由几个数组成,1,2,4,~~~cnt-2^K+1,k满足cnt-2^K+1>0的最大整数,体积和价值乘上相应的数就是相应物品的价值和体积,这样用这些物品能够表示1~~cnt所有的情况~~~这就转化成01背包了~~~ 代码: #include <iostream> #include <cstdio>…
题目:http://poj.org/problem?id=1276 多重背包模板题,没什么好说的,但是必须利用二进制的思想来求,否则会超时,二进制的思想在之前的博客了有介绍,在这里就不多说了. #include <iostream> #include <string.h> #include <stdio.h> #include <algorithm> #include <math.h> using namespace std; ],cnt[],d…
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…
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…
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…
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…
题目网址: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…
题目http://poj.org/problem?id=1276 分析 这是一个多重背包的问题,可以把请求的金额当作背包的重量,而货币的面值就是价值又是重量. 于是这个问题便很好理解背包了. #];;  ;  }  ZeroOnePack(amount],d[]; ;i,;i;}   来自为知笔记(Wiz)…
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…
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…
Time Limit: 1000MS   Memory Limit: 10000KB   64bit IO Format: %lld & %llu 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 di…
题意:略 多重背包 #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://www.cppblog.com/MatoNo1/archive/2011/07/05/150231.aspx多重背包的单调队列初中就知道了但一直没(不会)写二进制优化初中就写过一直不写会心虚就写一下这个吧朴素方程dp[i,j]=max(dp[i-1,j-w[i]*k]+c[i]*k) w[i]*k<=j k<=j div w[i]忽略第一维dp[j]=max(dp[j-w[i]*k]+c[i]*k)复杂度O(m2n)以下是大神原文:将决策下标按照模w0的余数进行分类,…
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…
个人心得:多重背包,自己根据转换方程写总是TLE,后面去网上看了二进制转换,不太理解: 后面仔细想了下,用自己的思想理解下把,就是将对应number,cash总和用二进制拆分, 然后全部装入到一个数组,这样子就可以减少循环,同时转变为01背包,这样子想把, 5 5,就变成了5,10,20,5然后用01背包互相取与不取也可以组成对应的k=1-5乘以5的值. 转换方式如下: ) { t[account++]=k*cash[i]; number[i]-=k; k=k*; } t[account++]=…
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…
转载地址:http://m.blog.csdn.net/blog/u010489766/9229011 题目链接:http://poj.org/problem?id=1276 题意:机器里面共有n种面额的钱币,每种各ni张,求机器吐出小于等于所要求钱币的最大值 解析1:这题大牛都用了多重背包,不过,我一同学想出了一种就这题而言特别简单有效的方 法.(话说我就认为这题本来就不需要用到背包的,因为n的范围只到10,太小了).方法就是对钱进行遍历,看这些钱一共能组成多少面额的钱,然后从 cash向下枚…
题意:多重背包模型  n种物品 每个m个  问背包容量下最多拿多少 这里要用二进制优化不然会超时 #include<iostream> #include<cstdio> #include<cstring> using namespace std; +; int dp[maxn]; ],c[]; int main(){ int n,m,maxnum; while(cin>>maxnum>>n){ int a,b; ; ;i<=n;i++){…
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24132 Accepted: 8446 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…
通过这道题我基本了解了利用二进制对多重背包问题进行优化的思想. Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24191   Accepted: 8466 Description A Bank plans to install a machine for cash withdrawal. The machine is able to deliver appropriate @ bills for…
最近的很多题解应该都是dp相关的了,emmm因为dp对我而言思考难度比较大,那么为了理顺自己的思路当然只能通过写blog整理了.愿我能成功搞定dp这个大关!(至少中等难度的dp要能够解决啊o(TヘTo)) 题意与分析 这条题目是一条明显的多重背包题目.遇到这种题目,我们首先简单的转化为01背包问题来解决.(思路:把$n_i$个$v_i$拆分开来)但是呢,有一个二进制优化可以采用,就是在这个拆分机制上.重点就是这段代码: while(num-k>=0) { things[cnt++]=d*k; n…
//Accepted 1100 KB 47 ms //多重背包 #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <cmath> #include <algorithm> using namespace std; /** * This is a documentation comment block * 如果有一天你坚持…
题意: 给出一个价值sum,然后给出n,代表n个方案,接着n对代表个数与价值,要求最接近sum,但不超过sum的价值. 思路: 多重背包,利用二进制拆分达到保证对于0..n间的每一个整数,均可以用若干个系数的和表示. 贴一发挫code-感受一下 //#include <bits/stdc++.h> #include<iostream> #include<string.h> #include<cstdio> #include<algorithm>…
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…
Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 27804   Accepted: 9915 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…
<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…
多重背包的模型,但一开始直接将N个物品一个一个拆,拆成01背包竟然T了!!好吧OI过后多久没看过背包问题了,翻出背包九讲看下才发现还有二进制优化一说........就是将n个物品拆成系数:1,2,4,8....*物品价值和空间的物品,在这题中只要乘上money[i]就行了,从二进制考虑发现,这样可以组成0~n中所有的数 #include <iostream> #include <cstdio> #include<string.h> using namespace std…
题意:直接说数据,735是目标值,然后3是后面有三种钱币,四张125的,六张五块的和三张350的. 思路:能够轻易的看出这是一个多重背包问题,735是背包的容量,那些钱币是物品,而且有一定的数量,是多种背包.但是做的时候总是超时.可能是因为m和n太大.然后可以通过二进制把它转化为01背包,因为将钱币的数量化为二进制,1   2    4直到数量减一.化成的二进制数字排列组合,可以组成任意钱币数量内的数字. 看代码: //二进制优化 多重背包转化为01背包 #include<stdio.h> i…