Bone Collector(复习01背包)】的更多相关文章

HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nmax 1005 using namespace std; int v[nmax],w[nmax],dp[nmax]; int main() { //freopen("in…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 54132    Accepted Submission(s): 22670 Problem Description Many years ago , in…
Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 28365    Accepted Submission(s): 11562 Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bo…
Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4739    Accepted Submission(s): 2470 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took pa…
Bone Collector Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bone Collector". This man like to collect varies of bones , such as dog's , cow's , also he went to the grave - The bone collector had a big…
Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 39532    Accepted Submission(s): 16385 Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bo…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave…
HDU2602 Bone Collector 01背包模板题 #include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> #define maxn 1005 int w[maxn], v[maxn], f[maxn]; int N, V, T; int _max(int a, int b){ if(a > b) return a; else return b; } i…
题意:求解01背包价值的第K优解. 分析: 基本思想是将每个状态都表示成有序队列,将状态转移方程中的max/min转化成有序队列的合并. 首先看01背包求最优解的状态转移方程:\[dp\left[ j \right] = \max \left\{ {dp\left[ j \right],dp\left[ {j - a\left[ i \right].w} \right] + a\left[ i \right].v} \right\}\] 如果要求第K优解,那么状态 dp[j] 就应该是一个大小为…
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/N 题目: Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also h…
题意:给出包裹的大小v,然后给出n块骨头的价值value和体积volume,求出一路下来包裹可以携带骨头最大价值 思路:01背包 1.二维数组(不常用 #include<iostream> #include<stdio.h> #include<math.h> using namespace std; ][]; int main() { int i,j; int t,n,_v;//测试用例个数,物品种类,背包大小 ],v[];//花费,价值 scanf("%d&…
意甲冠军:给出的数量和袋骨骼的数,然后给每块骨骼的价格值和音量.寻求袋最多可容纳骨骼价格值 难度;这个问题是最基本的01背包称号,不知道的话,推荐看<背包9说话> AC by SWS 主题链接 http://acm.hdu.edu.cn/showproblem.php?pid=2602 代码: #include<stdio.h> #include<string.h> typedef struct{ int w, v; }str; str s[1005]; int dp[…
Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave …The bone collector had a big bag with a volume of…
题意: 数据是常规的01背包,但是求的不是最大容量限制下的最佳解,而是第k佳解. 思路: 有两种解法: 1)网上普遍用的O(V*K*N). 2)先用常规01背包的方法求出背包容量限制下能装的最大价值m,再以m为背包容量再进行一次01背包,dp[j]表示当物品的组合价值为j时,它们的体积之和的最小量.那么就求出了所有可能的价值,从1-m都有,但是其中一些是求不出来的,也就是骨头的价值不能组合成这个数字,那么就得过滤掉. #include <iostream> #include <cstdi…
题意:01背包:有N件物品和一个容量为V的背包.每种物品均只有一件.第i件物品的费用是volume[i],价值是value[i],求解将哪些物品装入背包可使价值总和最大. 分析: 1.构造二维数组: dp[i][j]---前i件物品放入一个容量为j的背包可以获得的最大价值. dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - volume[i]] + value[i]);---(a) (1)dp[i - 1][j]---不放第i件物品,因此前i件物品放入一个容量…
此题就是在01背包问题的基础上求所能获得的第K大的价值. 详细做法是加一维去推当前背包容量第0到K个价值,而这些价值则是由dp[j-w[ i ] ][0到k]和dp[ j ][0到k]得到的,事实上就是2个数组合并之后排序,可是实际做法最好不要怎么做.由于你不知道总共同拥有多少种.而我们最多仅仅须要前K个大的即可了(由于可能2个数组加起来的组合数达不到K个),假设所有加起来数组开多大不清楚,所以能够选用归并排序中把左右2个有序数组合并成一个有序数组的方法来做.就是用2个变量去标记2个有序数组的头…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 解题思路:给出一个容量为V的包,以及n个物品,每一个物品的耗费的费用记作c[i](即该物品的体积),每一个物品的价值记作w[i], 我们用 f[v]来表示一个容量为v的包的总价值,这样最后我们只需要输出f[V]就能得出结果 则对于第i个物品,它可以放入背包,此时背包的容量变为v-c[i],背包的总价值变为f[v-c[i]]+w[i], 它也可以不放入背包,此时背包的容量还是v,背包的总价值不变…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 裸的... #include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <climits> #include <complex> #include <fstream> #include <casser…
分析 \(dp[i][j][k]\)为枚举到前i个物品,容量为j的第k大解.则每一次状态转移都要对所有解进行排序选取前第k大的解.用两个数组\(vz1[],vz2[]\)分别记录所有的选择情况,并选择其中前k大的更新当前的dp[i][k].因为dp[i]满足递增的特点,所以可以对两个数组顺序比较选择. #include<bits/stdc++.h> using namespace std; const int maxn = 1e3+5; const int INF = 0x3f3f3f3f;…
传送门 题目大意:01背包裸题. 复习01背包: 题目 有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总和最大. 题解: #include<iostream> #include<cstdio> #include<cstring> using namespace std; ],w[],v[]; int n,m,t; int main() { scanf("%d&quo…
Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave … The bone collector had a big bag with a volume of…
题目链接:pid=2602">HDU 2602 Bone Collector Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 28903    Accepted Submission(s): 11789 Problem Description Many years ago , in Teddy's h…
Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave …The bone collector had a big bag with a volume of…
Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4229    Accepted Submission(s): 2205 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took par…
Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 48618    Accepted Submission(s): 20269 Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bo…
Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 46460    Accepted Submission(s): 19338 Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bo…
Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 40331    Accepted Submission(s): 16756 Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bo…
题意:这题就是一个纯粹的裸01背包 分析:WA了好几次.01背包实现的一些细节没搞懂 1.为什么dp[i][j]赋初值为0而不是value[i].由于第i个石头可能不放! 2.在进行状态转移之前要dp[i][j]=dp[i-1][j],不然肯定会WA啊.想想就明确了 3.终于结果是dp[n][v],不是每次求mx,由于状态转移就是这么推的啊 代码: #include<iostream> #include<cstring> #include<cmath> using na…
 时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description Aiden马上要考试了,可他还没怎么复习,于是他决定临时抱佛脚.他列了N个知识点,并分析出了复习每个知识点所需的时间t以及可能获得的分数k.他现在还有T时间来复习,他希望选择正确的知识点来在最短的时间内获得最高的期望分数. 输入描述 Input Description 第一行,两个数,分别为N.T. 接下来的N行,每行两个数t.k,表示一个知识点…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意:把商品分成两半,如不能均分,尽可能的让两个数相接近.输出结果:两个数字a,b且a>=b. 思路:01背包. 先把商品的总价值计算出来,sum/2做为背包的容量. 然后讲同种商品的多件,存储为不同商品 同样价值的形式,也就是我们用一个一维数组来存储,不用一个二维或是两个一维数组来存. 感想:好久没有做背包的题目了,今天来做,忘了好多思路,这提醒着我,学习不能一直都在学新东西,也要及时的复习.…