题意:给定一个体积,和一些物品的价值和体积,问你最大的价值。

析:最基础的01背包,dp[i] 表示体积 i 时最大价值。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
//#include <tr1/unordered_map>
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
//using namespace std :: tr1; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e3 + 5;
const LL mod = 10000000000007;
const int N = 1e6 + 5;
const int dr[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
inline LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a%b); }
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int dp[maxn], a[maxn], c[maxn]; int main(){
int T; cin >> T;
while(T--){
scanf("%d %d", &n, &m);
for(int i = 0; i < n; ++i) scanf("%d", c+i);
for(int i = 0; i < n; ++i) scanf("%d", a+i); memset(dp, 0, sizeof dp);
for(int i = 0; i < n; ++i)
for(int j = m; j >= a[i]; --j)
dp[j] = Max(dp[j], dp[j-a[i]]+c[i]);
printf("%d\n", dp[m]);
}
return 0;
}

HDU 2602 Bone Collector (01背包DP)的更多相关文章

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

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

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

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

  3. HDU 2602 Bone Collector --01背包

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

  4. [HDU 2602]Bone Collector ( 0-1背包水题 )

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 水题啊水题 还给我WA了好多次 因为我在j<w[i]的时候状态没有下传.. #includ ...

  5. HDU 2602 Bone Collector (01背包问题)

    原题代号:HDU 2602 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 原题描述: Problem Description Many yea ...

  6. HDOJ(HDU).2602 Bone Collector (DP 01背包)

    HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...

  7. HDU 2602 Bone Collector 0/1背包

    题目链接:pid=2602">HDU 2602 Bone Collector Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...

  8. hdu 2602 Bone Collector(01背包)模板

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...

  9. HDU 2602 Bone Collector(经典01背包问题)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/O ...

随机推荐

  1. ALSA声卡08_从零编写之框架_学习笔记

    1.整体框架 (1)图示((DAI(全称Digital Audio Interface)接口)) 在嵌入式系统里面,声卡驱动是ASOC,是在ALSA驱动上封装的一层,包括以下三大块 (2)程序框架 m ...

  2. Druid.io系列(八):部署

    介绍 前面几个章节对Druid的整体架构做了简单的说明,本文主要描述如何部署Druid的环境 Imply提供了一套完整的部署方式,包括依赖库,Druid,图形化的数据展示页面,SQL查询组件等.本文将 ...

  3. 构建:vue项目配置后端接口服务信息

    背景 vue-cli脚手架生成的webpack标准模板项目 HTTP库使用axios 一.开发环境跨域与API接口服务通信 整体思路: 开发环境API接口请求baseURL为本地http://loca ...

  4. javascript示例一

    开发工具介绍 前端常用开发工具:sublime.visual Studio Code.HBuilder.Webstorm. 那么大家使用的PCharm跟WebStorm是JetBrains公司推出的编 ...

  5. Centos 6.5 下安装 Zabbix server 3.0服务器的安装及 监控主机的加入(2)

    一.Centos 6.5 下的Zabbix Server安装 上篇文章记录的是centos 7 下安装zabbix ,很简单.但是6.5上面没有可用的源直接安装zabbix,所以需要从别处下载.感谢i ...

  6. 华为交换机S5700 vty 0 4

    最佳答案   vty 0 4 代表有5条VTY线路 由0到4 这个要看设备的版本有的设备会有更多条VTY线路比如一些企业版的设备 显示用户界面 进入TELNET 设置模式 user-interface ...

  7. Vcf文件格式

    Vcf文件格式是GATK钟爱的表示遗传变异的一种文件格式. 就拿GATK给出的vcf例子说明吧,下面这个文件只表示了一个完整vcf文件的前几个SNP. 看上去确实有点复杂,那就把它分为两部分看吧,第一 ...

  8. 小酌Jmeter4.0新版本特性

    1.  首先下载打开jmeter4.0,说一个能感受到的视觉变化,如图, 黑色界面,不少朋友认为做技术黑色的东西看起来高上大一点,虽然这个观念有点肤浅,但似乎也有点道理,毕竟还是有不少朋友热衷于lin ...

  9. hadoop性能测试

    一.hadoop自带的性能基准评测工具 (一)TestDFSIO 1.测试写性能 (1)若有必要,先删除历史数据 $hadoop jar /home/hadoop/hadoop/share/hadoo ...

  10. Python,OpenGL生命游戏

    初学Python和OpenGL,练手的第一个小程序life.py,这个小程序在日后会不断调整,增加类.优化判断及操作 执行效果: 按正规生命游戏的规则: 1.周围生命等于3时产生生命 2.周围生命等于 ...