hdu 1059 Dividing(多重背包优化)】的更多相关文章

Dividing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 20635    Accepted Submission(s): 5813 Problem Description Marsha and Bill own a collection of marbles. They want to split the collection…
点击打开链接链接 Dividing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17544    Accepted Submission(s): 4912 Problem Description Marsha and Bill own a collection of marbles. They want to split the c…
Problem 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 could…
http://acm.hdu.edu.cn/showproblem.php?pid=1059 Dividing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 29901    Accepted Submission(s): 8501 Problem Description Marsha and Bill own a collection…
HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那么肯定不能被平分.若为偶数,则对valuesum/2为背包容量,全体石头为商品做完全背包.把完全背包进行二进制优化后,转为01背包即可. 代码总览 #include <iostream> #include <cstdio> #include <cstring> #inclu…
bitset做法 #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 //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int…
题意: 两个人共同收藏了一些石头,现在要分道扬镳,得分资产了,石头具有不同的收藏价值,分别为1.2.3.4.5.6共6个价钱.问:是否能公平分配? 输入: 每行为一个测试例子,每行包括6个数字,分别对应6种价钱的石头数目,比如101200代表价值为1的石头有1个,价值为2的石头有0个....价值为4的石头有2个.他们具有的石头数量的上限为2万个. 思路: 想用多重背包的方式解决,也想转01背包比较简单.直接转01背包会超时,得想办法.可以用多重背包的方法,用二进制来减少复杂度,应该可行.我用的是…
Problem 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 could…
多重背包模板- #include <stdio.h> #include <string.h> int a[7]; int f[100005]; int v, k; void ZeroOnePack(int cost, int weight) { for (int i = v; i >= cost; i--) if (f[i - cost] + weight > f[i]) f[i] = f[i - cost] + weight; } void CompletePack(…
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 could just spl…
链接:http://acm.hdu.edu.cn/showproblem.php?pid=2844 思路:多重背包 , dp[i] ,容量为i的背包最多能凑到多少容量,如果dp[i] = i,那么代表这个数能凑出来,ans+1: 实现代码: #include<bits/stdc++.h> using namespace std; ; int lis[M],dp[M],a[M],c[M]; int main() { int n,m,idx; while(cin>>n>>m…
题目大意:有n个单词,m的耐心,每个单词有一定的价值,以及学习这个单词所消耗的耐心,耐心消耗完则,无法学习.问能学到的单词的最大价值为多少. 题目思路:很明显的01背包,但如果按常规的方法解决时间复杂度O(n)=1e9,会超时.因为每个单词的价值和代价都不超过10,所以可以用二维数组G[V][W],记录价值为V,代价为W的单词的个数,并用多重背包的思路解决. #include<cstdio> #include<stdio.h> #include<cstdlib> #in…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1963 //多重背包 #include <cstdio> #include <cstring> #include <iostream> using namespace std; + ; #define N 15 long long dp[maxn], ans; int c[N], w[N], V; void Pack(int C, int W) { for(int i = C…
这道题是典型的多重背包的题目,也是最基础的多重背包的题目 题目大意:给定n和m, 其中n为有多少中钱币, m为背包的容量,让你求出在1 - m 之间有多少种价钱的组合,由于这道题价值和重量相等,所以就是dp[i] = i, 其中dp[i]表示当前背包容量为i 的时候背包能装的价值. 题目思路: 模板 二进制优化 话说那个二进制真的很奇妙,只需要2的1次方 到 2的k-1次方, 到最后在加上一项当前项的个数 - 2 的k次方 + 1,也就是这些系数分别为1; 2; 22 .....2k-1;Mi…
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 23728    Accepted Submission(s): 8363 Problem Description Nowadays, we all know that Computer College is the biggest department…
首先我们看一道有趣的题目 然后这道题很快想到是一个多重背包和无限背包混合体 那么我们就以这道题 来讨论一下多重背包的优化 首先我们看看朴素打法 memset(F,,]=; ;i<=N;i++) ;k<=C[i];k++) ;j>=;j--) ) F[j]=min(F[j],F[j-V[i]]+); 很简单 很好懂 但是这样做导致时间复杂度为O(N*C*T) 这道题来看超时到爆炸 那么我们考虑两种方法 第一种是像wph写的 首先贪心一会儿 然后再背包 答案大概在T到2*T的范围内 但是这种…
题意 给n个币的价值和其数量,问能组合成\(1-m\)中多少个不同的值. 分析 对\(c[i]*a[i]>=m\)的币,相当于完全背包:\(c[i]*a[i]<m\)的币则是多重背包,考虑用二进制优化解决.最后扫一遍\(dp[i]\)统计答案. import java.util.*; import java.math.*; public class Main{ static int MAXN = 100005; static int []dp = new int[MAXN]; static i…
使用一种二进制的优化, 可以完美的解决这题,<背包九讲>中说的非常好 但是还有一种线性复杂的算法. 应该算是该题很巧妙的解法 ;i++) { ;l--) { ) continue; ;k<=num[i]&&k*i+l<=total;k++) { if(dp[k*i+l]) break; // 这个剪枝瞬间将复杂度从N^2变成了N. dp[k*i+l]=; } } } 代码中total是我们要装满的容量, 循环的次序很重要. 当关键还是那一步剪枝 在附上一份用二进制优…
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19391    Accepted Submission(s): 5446 Problem Description Marsha and Bill own a collection of marbles. They want to split the collection among the…
题目链接 Problem 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 c…
Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6279    Accepted Submission(s): 2561 Problem Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. One d…
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…
点我看题目 题意: 将大理石的重量分为六个等级,每个等级所在的数字代表这个等级的大理石的数量,如果是0说明这个重量的大理石没有.将其按重量分成两份,看能否分成. 思路 :一开始以为是简单的01背包,结果写出来之后不对,因为以为从头开始往上加就行了,看能不能满足那个标准,后开才反应过来,还可以跳着加呢,让YN美女给我讲了一下,然后不小心手残了一下交了两遍WA之后终于AC了,其实就是用一个数组c来标记状态,c[i]表示 i 这个重量是可以用目前的石头表示出来的.而b数组表示的是这种石头的使用次数,也…
Q: 倍增优化后, 还是有重复的元素, 怎么办 A: 假定重复的元素比较少, 不用考虑 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…
Dividing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14861    Accepted Submission(s): 4140 Problem Description Marsha and Bill own a collection of marbles. They want to split the collection…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 35770    Accepted Submission(s): 15088 Problem Description 急!灾区的食物依…
link:http://acm.hdu.edu.cn/showproblem.php?pid=1059 最简单的那种 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cctype> #include <algorithm> #include <queue>…
Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8999    Accepted Submission(s): 3623 Problem Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. One…
Coins                                                                             Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silve…
Dividing 给出n个物品的价值和数量,问是否能够平分.…