poj 1276】的更多相关文章

链接: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 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…
转载地址:http://m.blog.csdn.net/blog/u010489766/9229011 题目链接:http://poj.org/problem?id=1276 题意:机器里面共有n种面额的钱币,每种各ni张,求机器吐出小于等于所要求钱币的最大值 解析1:这题大牛都用了多重背包,不过,我一同学想出了一种就这题而言特别简单有效的方 法.(话说我就认为这题本来就不需要用到背包的,因为n的范围只到10,太小了).方法就是对钱进行遍历,看这些钱一共能组成多少面额的钱,然后从 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…
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…
一道DP的题目,还是一道多重背包的题目,第一次接触. 题意:有现今cash,和n种钱币,每种钱币有ni个,价值为di,求各种钱币组成的不超过cash的最大钱数 思路:可以转换为0/1背包和完全背包来做. Memory: 648K Time: 16MS Language: C++ Result: Accepted #include <stdio.h> #include <iostream> #include <string.h> int cash,n; int num[1…
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…
735 3 4 125 6 5 3 350 //735的最大额,3种,4个125,6个5,3个350 633 4 500 30 6 100 1 5 0 1 735 0 0 3 10 100 10 50 10 10 735 630 0 0 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queu…
题意: 有n种纸币,已知每种纸币的面值和数量,求所能凑成的不超过cash的最大总面值. 分析: 这道题自己写了一下TLE了,好可耻.. 找了份比较简洁的代码抄过来了..poj1276 #include <cstdio> #include <cstring> ; + ; bool vis[maxp];//是否到达总面值i int used[maxp];//到达总面值i时,该种纸币所用的数量 int a[maxn], b[maxn];//每种纸币的数量以及面值 int cash, n;…