Gym 100917J---Judgement(01背包+bitset)】的更多相关文章

题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury of Berland regional olympiad in informatics does not trust to contest management systems, so the Berland regional programming contest is judged by th…
注意不能每个T都mem 不然会T #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define pb push_back #define inf 1e9 //std::ios::sync_with_stdio(false); using namespace std; //priority_qu…
A - Coins Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Description standard input/output Hasan and Bahosain want to buy a new video game, they want to share the expenses. Hasan has a set of N coins and Bahosain has a…
/*首先考虑如何计算一个点的可能凑出的值,这就是一个01可行性背包问题那么再拓展到一段区间[1..n]的点上,每个query都可以看做是一段区间上的点[l,r]加上一个体积为x的物品,转换到01背包上就是进行一次更新那么用线段树来维护每个query的区间更新 每个位置(区间)维护一个bitset,每次加入a都进行一次01背包 用线段树来维护区间的bitset,表示一段区间能组成的值 但是没法用lazy,每次区间更新只能停留在一段区间可以把每次停留在区间的数a用vector保存下来,当进行完所有的…
口胡一种别的解法: 三重退背包,g1[j]k]表示不选x的选了j件物品,体积为k的方案数,g[0][0] = 1 , g1[j][k]=dp[j][k]-g1[j-1][k-a[x]] 然后按这样再退三层,最后看g3[10][87]的方案数是否非0即可,这样复杂度是O(50*50*50*10*87) 如果直接枚举删掉的数,然后用可行性二维01背包做 复杂度是O(50*50*50)*O(n*10*87) 再加上bitset优化第二维 复杂度/32 ,由于n比较小,所以也差不多 /* 在n个数里找到…
01背包变形,注意dp过程的时候就需要取膜,否则会出错. 代码如下: #include<iostream> #include<cstdio> #include<cstring> using namespace std; #define MAXW 15005 #define N 155 #define LL long long #define MOD 1000000007 int w1[N],w2[N]; LL dp1[MAXW],dp2[MAXW]; int main(…
Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4178    Accepted Submission(s): 2174 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took pa…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2639 题意:求01背包的第k优解 dp(i, j)表示容量为j时的i优解 对于第二维的操作和01背包几乎一样,只是我们只需要关注每一次取的前k大个即可. #include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <climits> #…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 许多有价值的物品,有重复.问如何将他们分成两堆,使两堆价值之差最小. 对价值求和,转换成01背包,做一次,相当于一堆选物品使得最接近一半.然后这个结果和用价值和作差的结果就是两堆的价值,此时价值只差最小. #include <algorithm> #include <iostream> #include <iomanip> #include <cstring&g…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2546 先找出最贵的那个菜,这个菜一定是最后买的那个.然后再在前n-1个菜里做01背包.找出不超过m-5的最大价值.然后用m减去这两个值即可. #include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <climits> #includ…