POJ1742 Coins 背包】的更多相关文章

题目大意:给出一些钱币的价值和对应的数目,求在一定价值限定下这些钱币能凑成的价值数. 本题用多重背包直接拆分或二进制拆分法都太慢.说起处理一组物品,完全背包可算是比较效率高的,但是本题中物体的数目是有限的呀!因此我们可以对于每一个物品(钱币)i设置一个used数组,used[j]表示在凑成价值j的各个钱币中,需要钱币i的数量是多少.vis是价值是否能够凑成的数组. 只有当: vis[j]==false(如果价值j已经被其它钱币所凑成,则把当前的i钱币用于凑成以后的价值可能性会更高) vis[j-…
前言 大名鼎鼎的男人八题,终于见识了... 题面 http://poj.org/problem?id=1742 分析 § 1 多重背包 这很显然是一个完全背包问题,考虑转移方程: DP[i][j]表示用前i种硬币能否取到金额j,ture表示可以,false表示不行. 则有 DP[i][j] = DP[i - 1][j] | DP[i - 1][j - k * Ai], 0 ≤ k ≤ Ci, j - k * Ai ≥ 0 这是一个O(N3)的算法,考虑到数据范围1 ≤ N ≤ 100, M ≤…
Coins Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 34814   Accepted: 11828 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 Time Limit: 3000MS   Memory Limit: 30000K Total Submissions:43969   Accepted: 14873 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…
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 pri…
Vjudge传送门 $Sol$ 首先发现这是一个多重背包,所以可以用多重背包的一般解法(直接拆分法,二进制拆分法...) 但事实是会TLE,只能另寻出路 本题仅关注“可行性”(面值能否拼成)而不是“最优性”,这是一个特殊之处. 从这里找优化 在“最优性”的问题中,$f[j]$从$f[j]$或$f[j-a[i]]$中转移而来:而在这样的“可行性”问题中,其实只要$f[j]$可行,我们就可以不用考虑$f[j-a[i]$了,也可以反过来说. 于是我们可以考虑一种贪心策略,设$used[j]$表示$f[…
/* 这题卡常数.... 二进制优化或者单调队列会被卡 必须+上个特判才能过QAQ 单调队列维护之前的钱数有几个能拼出来的 循环的时候以钱数为步长 如果队列超过c[i]就说明队头的不能再用了 拿出来 时刻维护sum表示之前的+v[i]能凑出j来的有几种 注意先进队在更新f */ #include<iostream> #include<cstdio> #include<cstring> #define maxm 100010 #define maxn 110 using…
The Fewest Coins Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6299   Accepted: 1922 Description Farmer John has gone to town to buy some farm supplies. Being a very efficient man, he always pays for his goods in such a way that the sm…
http://poj.org/problem? id=1742 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…
题意大概是:给出N个硬币, 面值为a_i, 问要凑成X元哪些硬币是不可或缺的.1 ≤ N ≤ 200, 1 ≤ x ≤ 10^4 直接枚举, 然后就是01背包了. 为了不让复杂度多乘个N, 我们就从左往右, 从右往左分别dp一次.这样判断一个硬币就是O(X).总时间复杂度O(NX) ----------------------------------------------------------------------------- #include<bits/stdc++.h>   usi…