Bone Collector
来源:互联网 发布:自动化编程语言有哪些 编辑:程序博客网 时间:2024/05/22 12:19
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 ?
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
Author
Teddy
Source
HDU 1st “Vegetable-Birds Cup” Programming Open Contest
题意:本题是要求最大价值的问题,属于01背包问题。
代码:
#include<stdio.h>#include<math.h>#include<string.h>int max(int a,int b){return a>b?a:b;}int main(){int i,j,k,n,m,p;int w[1100],v[1100],c[1100];int s[1100];scanf("%d",&n);while(n--){memset(s,0,sizeof(s));scanf("%d%d",&m,&p);for(i=0;i<m;i++)scanf("%d",&w[i]);for(i=0;i<m;i++)scanf("%d",&v[i]);for(i=0;i<m;i++)for(j=p;j>=v[i];j--)s[j]=max(s[j],s[j-v[i]]+w[i]);printf("%d\n",s[p]);}return 0;}
0 0
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- Bone Collector
- uva live 12846 A Daisy Puzzle Game
- 数据结构 第五章 树和二叉树
- Android v4包中的 SwipeRefreshLayout 官方的下拉刷新组件
- POJ3132——Sum of Different Primes
- Servlet(三)HttpServlet
- Bone Collector
- 定时器
- Hadoop WordCount 程序的一些问题级解决办法
- 谨防串行的状态报告会
- 数据结构 第五章 树和二叉树
- PHP 语法大全(总结)
- 数字图像处理--通过矩阵,简化操作(旋转,平移,缩放,切边....)
- Python和C|C++的混编(二):利用Cython进行混编
- 求1~任意数的质数