codevs 5429 多重背包】的更多相关文章

5429 多重背包 http://codevs.cn/problem/5429 分析: f[i]=g[j-k*siz[i]]+k*val[i]; 发现一个状态d只会更新,d+siz[i],d+2*siz[i]...d+k*siz[i],所以可以枚举每个d,d<m,然后将d的倍数提出来(就是一个剩余系),然后这些状态就是随便转移了,然后单调队列优化.复杂度O(nm). 代码: #include<cstdio> #include<algorithm> #include<cs…
单调队列优化. 好像有点烦...调了许久. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 7050 using namespace std; long long n,m,v[maxn],w[maxn],c[maxn],up[maxn],q[maxn],l,r,ret1,ret2,val[maxn],dp[maxn]; void ge…
先通过并查集处理出来有多少种不同的集合,每一个集合有多少人.一定要不要忘记了与别的没有联系的独立点. 并查集的时候能够通过hash处理出来每一个数目同样的集合的个数. 这样以人数为权值.个数为限制进行多重背包,结果就是答案. 题目链接:http://codevs.cn/problem/3372/ #include <algorithm> #include <iostream> #include <stdlib.h> #include <string.h> #…
题目描述 小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…