hdu 2602 Bone Collector
来源:互联网 发布:标题优化软件哪个好 编辑:程序博客网 时间:2024/06/11 19:05
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 ?
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.
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 231).
Sample Input
15 101 2 3 4 55 4 3 2 1
Sample Output
14就是01背包真接上代码#include<stdio.h>int c[3500],w[3500],f[13000];int main(){int i,j,k,n,v,m,t;scanf("%d",&t);while(t--){scanf("%d%d",&n,&m);for(i=0;i<=m;i++)f[i]=0;for(i=0;i<n;i++)scanf("%d",w+i);for(i=0;i<n;i++)scanf("%d",c+i);for (i = 0; i < n; ++i){for (v = m; v >= c[i]; --v) //注意这里的V是从大到小c[i]可优化为bound,bound = max {V - sum c[i,...n],c[i]}{f[v] = (f[v] > f[v - c[i]] + w[i]?f[v] : f[v - c[i]] + w[i]);}}printf("%d\n",f[m]);}return 0;}
- HDU 2602 Bone Collector
- hdu 2602 Bone Collector
- hdu 2602 Bone Collector
- hdu 2602 Bone Collector
- HDU 2602 - Bone Collector
- HDU 2602 Bone Collector
- hdu 2602 Bone Collector
- HDU 2602 Bone Collector
- hdu 2602 Bone Collector
- hdu 2602 Bone Collector
- Hdu 2602 - Bone Collector
- hdu 2602 Bone Collector
- hdu 2602 Bone Collector
- Hdu 2602 Bone Collector
- Hdu 2602 Bone Collector
- hdu 2602 Bone Collector
- hdu - 2602 - Bone Collector
- hdu 2602 Bone Collector
- 费马小定理的小运用
- Android 的main.mk完整分析 .
- Android编译系统(四):Android 编译系统框架分析及main.mk分析 .
- JAVA 虚拟机体系结构
- C语言的volatile关键字分析
- hdu 2602 Bone Collector
- 算法和数据结构提纲
- poj3624 Charm Bracelet
- Increase limits on sockets on Mac OS X
- 孙鑫VC++深入详解:Lesson6 Part1 -- CheckMenuItem,子菜单项上添加位图,禁用子菜单项,删除整个菜单,和加载菜单
- asp.net mvc 网站收集
- cce原来跟gpm有冲突
- JavaEE的13种核心技术规范
- 读书笔记-葡萄酒