Bone Collector

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 21   Accepted Submission(s) : 6
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 V ,and along his trip of collecting there are a lot of
bones , obviously , different bone has different value and different volume, now
given the each bone’s value along his trip , can you calculate out the maximum
of the total value the bone collector can get ?
 
Input
The first line contain a integer T , the number of
cases. Followed by T cases , each case three lines , the first line contain two
integer N , V, (N <= 1000 , V <= 1000 )representing the number of bones
and the volume of his bag. And the second line contain N integers representing
the value of each bone. The third line contain N integers representing the
volume of each bone.
 
Output
One integer per line representing the maximum of the
total value (this number will be less than 2[sup]31[/sup]).
 
Sample Input
1
5 10
1 2 3 4 5
5 4 3 2 1
 
Sample Output
14
题解:也就01背包;
代码:
 #include<stdio.h>
#include<string.h>
#define max(a,b) (a>b?a:b)
int f[];
int val[];
int cos[];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
memset(f,,sizeof(f));
memset(val,,sizeof(val));
memset(cos,,sizeof(cos));
int n,v;
scanf("%d%d",&n,&v);
int i,j;
for(i=;i<=n;i++)
scanf("%d",&val[i]);
for(j=;j<=n;j++)
scanf("%d",&cos[j]);
for(i=;i<=n;i++)
{
for(j=v;j>=cos[i];j--)
{
// f[j]=f[j-1];
// if(j>=cos[i])
f[j]=max(f[j],f[j-cos[i]]+val[i]);
}
}
printf("%d\n",f[v]);
}
return ;
}

记忆化搜索;

ac代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
#define SD(x) scanf("%lf",&x)
#define P_ printf(" ")
typedef long long LL;
const int MAXN=;
int dp[MAXN][MAXN],w[MAXN],p[MAXN];
int dfs(int i,int v){
if(dp[i][v])return dp[i][v];
if(i==||v<)return ;//
if(w[i]>v)dp[i][v]=dfs(i-,v);
else dp[i][v]=max(dfs(i-,v),dfs(i-,v-w[i])+p[i]);//
return dp[i][v];
}
int main(){
int T,N,M;
SI(T);
while(T--){
SI(N);SI(M);
for(int i=;i<=N;i++)SI(p[i]);
for(int i=;i<=N;i++)SI(w[i]);
mem(dp,);
printf("%d\n",dfs(N,M));
}
return ;
}

Bone Collector(01背包+记忆化搜索)的更多相关文章

  1. 01背包-记忆化搜索到成型的DP

    记忆化搜索 #include<bits/stdc++.h> using namespace std; typedef long long ll; int n,W; int dp[105][ ...

  2. HDU 2602 Bone Collector(01背包裸题)

    Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  3. hdu2602 Bone Collector 01背包

    Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like ...

  4. HDU 2602 - Bone Collector - [01背包模板题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Many years ago , in Teddy’s hometown there was a ...

  5. [原]hdu2602 Bone Collector (01背包)

    本文出自:http://blog.csdn.net/svitter 题意:典型到不能再典型的01背包.给了我一遍AC的快感. //=================================== ...

  6. hdu2602 Bone Collector (01背包)

    本文来源于:http://blog.csdn.net/svitter 题意:典型到不能再典型的01背包.给了我一遍AC的快感. //================================== ...

  7. HDU 2602 Bone Collector --01背包

    这种01背包的裸题,本来是不想写解题报告的.但是鉴于还没写过背包的解题报告.于是来一发. 这个真的是裸的01背包. 代码: #include <iostream> #include < ...

  8. ACM HDU Bone Collector 01背包

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 这是做的第一道01背包的题目.题目的大意是有n个物品,体积为v的背包.不断的放入物品,当然物品有 ...

  9. 解题报告:hdu2602 Bone collector 01背包模板

    2017-09-03 15:42:20 writer:pprp 01背包裸题,直接用一维阵列的做法就可以了 /* @theme: 01 背包问题 - 一维阵列 hdu 2602 @writer:ppr ...

随机推荐

  1. MFC子窗口和父窗口(SetParent,SetOwner)

    一.概念和区别 在windows系统中,每个窗口对象都对应有一个数据结构,形成一个list链表.系统的窗口管理器通过这个list来获取窗口信息和管理每个窗口.这个数据结构中有四个数据用来构建list, ...

  2. 命令行解释器(shell)

    unix> ./hello hello world unix> ll 显示当前目录下文件信息. shell为命令行解释器,第一个单词可以是内置的外壳命令,也可以是一个可执行文件名.

  3. poj 1094 Sorting It All Out_拓扑排序

    题意:是否唯一确定顺序,根据情况输出 #include <iostream> #include<cstdio> #include<cstring> #include ...

  4. hdu 4627 The Unsolvable Problem(暴力的搜索)

    Problem Description There are many unsolvable problem in the world.It could be about one or about ze ...

  5. MTK Android4.0.3 ICS 添加缅甸语Myanmar

    最近几个项目需要添加缅甸语,借助网络资源,同时结合自身实践,成功添加缅甸语,现分享经验如下. 一. 前期工作: 准备Myanmar字库,下载地址:http://www.myordbok.com/mya ...

  6. C#整理2——C#的输入输出及基本类型

    //输出 Console.WriteLine("摩西摩西"); Console.Write("hollo");不带回车的 注意: 1.注意大小写敏感.(快捷键操 ...

  7. ASP.NET打印EXCEl报表技术总结

    序言:我们在做企业项目或者一些管理系统的时候往往会用到导出到excel报表这项功能,下面我介绍的是用windows自带的excel来打印 首先必须引入:Interop.Excel.dll.Intero ...

  8. javascript模式——Prototype模式

    GoF权威的解释是,原型模式是一种通过对一个对象的克隆,创建基于这个对象的多种对象的模式. 为了实现这种原型模式,可以直接使用ECMAScript 5 中的方法Object.create.它不紧可以创 ...

  9. Android学习之listview的下拉刷新、上拉载入

    本例是在上例的基础上完成的.本例实现的listview上拉载入.下拉刷新功能,是在开源网站上别人写好的listview,主要是对listview的控件进行重写,添加了footer和header. 1. ...

  10. js糟粕

    正在看<javascript语言精粹>,遇到明显的特点就记录下来,以防看了白看(噗噗~) 为了不误导,形成错误印象,文中 ‘错误设计‘ 写成 ‘现有设计’,’正确设计‘ 写成 ’期待设计‘ ...