Knapsack CodeForces - 1132E (多重背包)】的更多相关文章

可以将大量同种物品合并为$lcm$来优化, 复杂度$O(nlcm^2)$, 好像可以用bitset优化到$O(nlcm^2/\omega)$, 但是没看太懂 const int L = 840, M = L*8; ll w; ll dp[10][M]; void chkmax(ll &x,ll y) {x=max(x,y);} int main() { scanf("%lld", &w); memset(dp, -1, sizeof dp); dp[0][0] = 0;…
题目链接:http://codeforces.com/problemset/problem/106/C 根据题意列出式子,设每种蛋糕做了xi个,则对于每种材料bi*xi<=ai. 对于dough,有sum(ci*xi) + c0*x0 <=n. 要使得sum(di*xi)+d0*x0最大,立即转化为多重背包,有xi<=ai/bi.这是物品i的数量限制,背包的容量为n,每件物品的体积为ci,价值为di.由于数据比较弱,就算直接拆分成0-1背包都可以做.. 贴代码: #include<…
https://codeforces.com/contest/1132/problem/E 题意 有8种物品,重量是1~8,每种数量是\(cnt[i]\)(1e16),问容量为W(1e18)的背包最多能装多少重量 题解1 多重背包二进制拆分物品转换成01背包,用map来剪枝掉无用的状态 #include<bits/stdc++.h> #define ll long long using namespace std; map<ll,bool>f,g; ll a[10],W,s[100…
题目链接: F. PolandBall and Gifts time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output It's Christmas time! PolandBall and his friends will be giving themselves gifts. There are n Balls overall.…
F. PolandBall and Gifts   It's Christmas time! PolandBall and his friends will be giving themselves gifts. There are n Balls overall. Each Ball has someone for whom he should bring a present according to some permutation p, pi ≠ i for all i. Unfortun…
pro:给定N个点,M条边,现在你要给一些连通块加边,使得至少存在一个连通块的大小是由4和7组成的数字.问至少加边数量. sol: 看似一个很难的题目.  首先不要想太难了,还是应该想能不能用背包做. 我们把块的大小相同的分到一组,就可以分组背包了. 然后注意到组别的大小其实不会太大,因为1*1+2*2+3*3+4*4+x*x<=1e5;   x是1e2级别的. 所以做100次多重背包. 总的复杂度也才O(100*N*K),K是个比较小的常数,真正的复杂度小于这个: #include<bits…
题目描述 小S坚信任何问题都可以在多项式时间内解决,于是他准备亲自去当一回旅行商.在出发之前,他购进了一些物品.这些物品共有n种,第i种体积为Vi,价值为Wi,共有Di件.他的背包体积是C.怎样装才能获得尽量多的收益呢?作为一名大神犇,他轻而易举的解决了这个问题. 然而,就在他出发前,他又收到了一批奇货.这些货共有m件,第i件的价值Yi与分配的体积Xi之间的关系为:Yi=ai*Xi^2+bi*Xi+ci.这是件好事,但小S却不知道怎么处理了,于是他找到了一位超级神犇(也就是你),请你帮他解决这个…
题意:假设有x1个字母A, x2个字母B,..... x26个字母Z,同时假设字母A的价值为1,字母B的价值为2,..... 字母Z的价值为26.那么,对于给定的字母,可以找到多少价值<=50的单词呢?单词的价值就是组成一个单词的所有字母的价值之和,比如,单词ACM的价值是1+3+14=18,单词HDU的价值是8+4+21=33.(组成的单词与排列顺序无关,比如ACM与CMA认为是同一个单词). 题解:把26个字母看做26种背包,有个数有价值,求价值不超过50的所有可能个数,就是标准的多重背包.…
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…
http://poj.org/problem?id=3260   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 smallest number of coins changes hands, i.e., the number of coins he…
http://poj.org/problem?id=1787   描述 Charlie is a driver of Advanced Cargo Movement, Ltd. Charlie drives a lot and so he often buys coffee at coffee vending machines at motorests. Charlie hates change. That is basically the setup of your next task. Yo…
单调队列优化DP:http://www.cnblogs.com/ka200812/archive/2012/07/11/2585950.html 单调队列优化多重背包:http://blog.csdn.net/flyinghearts/article/details/5898183 传送门:hdu 3401 Trade /************************************************************** Problem:hdu 3401 Trade Us…
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…
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…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5445 题意:多重背包 分析:f[i][j]=max(f[i-1][j-k*w[i]]+k*v[i]) 将j写成w[i]的余数形式 即j=a*w[i]+b 则f[i][j]=max(f[i-1][(a-k)*w[i]+b]-(a-k)*v[i])+a*v[i] 其中0<=k<=min(num[i],j/w[i]) 再将a-k换成k 则f[i][j]=max(f[i-1][(k*w[i]+b]-k*v[i…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1059 之前写过一个多重背包二进制优化的博客,不懂请参考:http://www.cnblogs.com/a-clown/p/5953847.html //之前WA了无数次..心塞... 两种思路,都可以. 代码1: #include<iostream> #include<cstdio> #include<cstring> #include<cmath>…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2191 多重背包:有N种物品和一个容量为V的背包.第i种物品最多有n[i]件可用,每件费用是c[i],价值是w[i]. 求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大. 有两种思路,其中一种是转换为01背包,还有一种就是转换为01背包和完全背包. 转换为01背包代码: //转换为01背包的代码 #include<iostream> #include<al…
Problem Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. One day Hibix opened purse and found there were some coins. He decided to buy a very nice watch in a nearby shop. He wanted to pay the exact price(witho…
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  HDU 2844 不能用最基础的多重背包模板:会超时的!!! 之后看了二进制优化了的多重背包. 就是把多重转变成01背包: 具体思路见:http://www.cnblogs.com/tt123/p/3280521.html #include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> using namespace std; ],a1[],a[],b[];…
http://acm.hdu.edu.cn/showproblem.php?pid=2191 New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院关于2015年杭电ACM暑期集训队的选拔 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 17930    Accepted…
题目描述 在之前的上机中,零崎已经出过了01背包和完全背包,也介绍了使用-1初始化容量限定背包必须装满这种小技巧,接下来的背包问题相对有些难度,可以说是01背包和完全背包的进阶问题. 多重背包:物品可以有0-n件. 对于第i种物品,我们有取0件,1件…n [ i ] 件共n [ i ] +1种策略,状态转移方程为f [ i ] [ v ] = max { f [ i - 1 ] [ v - k × c [ i ] ] + k × w [ i ] | 0 <=k<= n [ i ] }.在这里,…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1171 Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) 问题描述 Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you…
以前只会写多重背包的原版,渣的不行,为了做此题不得不学习了一下,发现其实也不难,只要理解了方法就好多了(PS:其实和倍增挺像的) 8756:砝码称重V2 总时间限制: 1000ms 内存限制: 65536kB 描述 设有1g.2g.3g.5g.10g.20g的砝码各若干枚(其总重<=100,000),要求:计算用这些砝码能称出的不同重量的个数,但不包括一个砝码也不用的情况. 输入 一行,包括六个正整数a1,a2,a3,a4,a5,a6,表示1g砝码有a1个,2g砝码有a2个,--,20g砝码有a…
解题思路: 多重背包:第 i 件物品有 j 个可用. 本题中 第 p[i] 类大米 有 c[i] 袋大米可买 ,故本题为多重背包. n(总钱数).m(种类) p[i] 单价 h[i] 重量 c[i] 本种类的总袋数 01背包解题伪代码: for i=1-m  //种类 for j=1-c[i]  //每种的最大袋数 for k=n-p[i] //总钱数-当前种类的单价 f[k]=min{f[k],f[k-p[i]]+h[i]} #include<bits/stdc++.h> using nam…
题意:有几个砖,给出高度,能放的最大高度和数目,求这些砖能垒成的最大高度 依据lim排个序,按一层一层进行背包 #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> using namespace std; ; int n,m,t; int dp[maxn]; struct No…
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…
题意:价值分别为1,2,3,4,5,6的物品个数分别为a[1],a[2],a[3],a[4],a[5],a[6],问能不能分成两堆价值相等的. 解法:转化成多重背包 #include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> using namespace std; ]; ]; int nValue; //0-1背包,代价为cost,获得的价值为weight void…
前几天刚回到家却发现家里没网线 && 路由器都被带走了,无奈之下只好铤而走险尝试蹭隔壁家的WiFi,不试不知道,一试吓一跳,用个手机软件简简单单就连上了,然后在浏览器输入192.168.1.1就能看到他的路由器的一切信息,包括密码,然后打开笔记本……好了,废话不多说,能连上网后第一时间当然是继续和队友之前约好的训练了. 今天翻看到之前落下的一道混合背包题目,然后在草稿本上慢慢地写递推方程,把一些细节细心地写好…(本来不用太费时间的,可是在家嘛,一会儿妈走来要我教她玩手机,一会儿有一个亲戚朋…