HDUOJ--Bone Collector
Bone Collector
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 21463 Accepted Submission(s): 8633
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 ?
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.
背包问题.....一定要多练习...
代码:----
#include<stdio.h>
#include<string.h>
#define maxn 1005
int dp[maxn],arr[maxn][];
int max(int a,int b)
{
return a>b?a:b;
} void zeroonepack(int cost ,int value,int v)
{
for(int i=v;i>=cost;i--)
dp[i]=max(dp[i],dp[i-cost]+value); }
int main()
{
int t,n,v ,i;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&v);
memset(dp,,sizeof dp);
for(i=;i<n;i++)
{
scanf("%d",arr[i]+);
}
for(i=;i<n;i++)
{
scanf("%d",arr[i]+);
}
for(i=;i<n;i++)
zeroonepack(arr[i][],arr[i][],v);
printf("%d\n",dp[v]);
}
return ;
}
优化后代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct st
{
int a;
int b;
};
typedef struct st sta;
int main()
{
int test,n,v,i,j;
scanf("%d",&test);
while(test--)
{
scanf("%d%d",&n,&v);
int *dp =(int *)malloc(sizeof(int)*(v+));
sta *stu =(sta *)malloc(sizeof(sta)*(n+));
for(i=;i<n;i++)
scanf("%d",&stu[i].a);
for(i=;i<n;i++)
scanf("%d",&stu[i].b);
for(i=;i<=v;i++)
dp[i]=; for(i=;i<n;i++)
{
for(j=v ; j>=stu[i].b ; j--)
{
if(dp[j]<dp[j-stu[i].b]+stu[i].a)
dp[j]=dp[j-stu[i].b]+stu[i].a;
}
}
printf("%d\n",dp[v]);
free(dp);
free(stu);
}
return ;
}
HDUOJ--Bone Collector的更多相关文章
- hdu 2602 Bone Collector(01背包)模板
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...
- HDU 2602 Bone Collector WA谁来帮忙找找错
Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...
- Bone Collector(01背包)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/N 题目: Description Many year ...
- HDU 3639 Bone Collector II(01背包第K优解)
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- Bone Collector II
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 2602 Bone Collector (简单01背包)
Bone Collector http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , i ...
- hdu 2602 Bone Collector 背包入门题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 题目分析:0-1背包 注意dp数组的清空, 二维转化为一维后的公式变化 /*Bone Coll ...
- hdu 2639 Bone Collector II
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 杭电 2602 Bone Collector
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 2602 Bone Collector
http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- 程序员眼中的RSA算法
RSA算法是数学应用于实际的一项伟大发明,起数学过程相对而言还是比较专业的,有兴趣可以看看. RSA算法的证明过程,详见:http://www.ruanyifeng.com/blog/2013/06/ ...
- C++中的public、private、protected成员继承问题
我是C++菜鸟,刚学了一点C++. 先看例子1: /* Item.h */ #include <iostream> #include <string> class It ...
- insert-delete-getrandom-o1
// 参考了下面一些讨论的解法 // https://discuss.leetcode.com/topic/53235/java-with-hashtable-arraylist/2 class Ra ...
- python部分重点底层源码剖析
Python源码剖析—Set容器(hashtable实现) python源码剖析(内存管理和垃圾回收)
- iOS开发-搜索栏UISearchBar和UISearchController
iOS中UISearchDisplayController用于搜索,搜索栏的重要性我们就不说了,狼厂就是靠搜索起家的,现在越来越像一匹没有节操的狼,UC浏览器搜索栏现在默认自家的神马搜索,现在不管是社 ...
- nGrinder3.4 性能测试框架安装
转载:https://blog.csdn.net/mbugatti/article/details/53782070 nGrinder3.4 (2016.05.24) 支持JDK1.8 github地 ...
- swift语言实现单例模式
Swift实现单例模式 单例模式在各个语言中都有实现,swift语言推出已经几天了.通过这几天的看文档.特奉上写的Swift的单例实现,供大家学习交流,欢迎指正. ---若转载请注明出处,本人Gith ...
- 监听器(web基础学习笔记二十二)
一.监听器 监听器是一个专门用于对其他对象身上发生的事件或状态改变进行监听和相应处理的对象,当被监视的对象发生情况时,立即采取相应的行动.监听器其实就是一个实现特定接口的普通java程序,这个程序专门 ...
- Modifying a Request or Response
To make custom changes to web requests and responses, use FiddlerScript to add rules to Fiddler's On ...
- VarPtr 得到地址 指针
在Basic语言演变成QBasic,然后到Visual Basic之前,VarPtr函数就已经存在了.开始,这个函数存在于VB运行库1.0版中.通过声明可以调用这个函数: Declare Functi ...