HDOJ -- 2602 Bone Collector

 Bone Collector
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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 31).

Sample Input

1
5 10
1 2 3 4 5
5 4 3 2 1

Sample Output

14

01背包基础入门题,对于01背包问题,一个显著的特点是:每种物品装入背包的数量要么是0要么是1。如果用V[i]表示第i件物品所占用的背包的体积,W[i]表示第i件物品的价值,用二维数组dp[i][j]来表示前i件物品恰好放入体积为j的背包中所获得的最大价值,那么:
1、当i不放入背包时,那么背包里就只有前i-1个物品,此时dp[i][j]=dp[i-1][j];
2、当i放入背包中,那么未放入之前(即前i-1个物品)的体积为j-V[i],价值为dp[i-1][j-V[i]],此时dp[i][j]=dp[i-1][j-V[i]]+W[i];
显然要取其中的最大者,于是动态方程:dp[i][j]=max(dp[i-1][j],dp[i-1][j-V[i]]+W[i])
对于这道题,用一维数组也可以解决。用dp[i]表示背包体积为i时,所装的最大价值,然后逐个物品判断就行了,不过还是感觉二维的容易理解。
一位数组代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int t,n,v;
	int dp[1010],V[1010],w[1010];
	scanf("%d",&t);
	while(t--){
		scanf("%d%d",&n,&v);
		for(int i=0;i<n;i++)
			scanf("%d",&w[i]);
		for(int i=0;i<n;i++)
			scanf("%d",&V[i]);
		memset(dp,0,sizeof(dp));
		for(int i=0;i<n;i++)
			for(int j=v;j>=V[i];j--)//确保背包剩余体积大于即将要放入的物品的体积 
				dp[j]=max(dp[j],dp[j-V[i]]+w[i]);
		printf("%d\n",dp[v]);
	}
	return 0;
}

二维数组代码:
#include<stdio.h>  
#include<string.h> 
#include<algorithm>
using namespace std; 
int dp[1002][1002];//要定义在main函数外,否则爆内存!! 
int main(){
    int i,j,t,n,v;  
    int W[1002],V[1002];  
    scanf("%d",&t);  
    while(t--){
        scanf("%d%d",&n,&v);  
        for(i=0;i<n;i++)  
            scanf("%d",&W[i]);  
        for(i=0;i<n;i++)  
            scanf("%d",&V[i]);  
        memset(dp,0,sizeof(dp));  
        for(i=0;i<V[0];i++)  
            dp[0][i]=0; //当背包体积小于第一个物品体积时,价值为0 
        for(i=V[0];i<=v;i++)  
            dp[0][i]=W[0];//反之为第一个物品的价值 
        for(i=1;i<n;i++){//从1开始判断 
            for(j=0;j<V[i];j++)  
                dp[i][j]=dp[i-1][j];//小于物品i的体积时,i物品无法放入  
            for(j=V[i];j<=v;j++)  
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-V[i]]+W[i]);//反之取最大者 
        }  
        printf("%d\n",dp[n-1][v]);  
    }  
    return 0;  
}


内容概要:本文系统介绍了标准化和软件知识产权的基础知识,涵盖标准化的基本概念、分类、标准代号、国际标准的采用原则及程度,重点讲解了信息技术标准化、ISO与IEC等国际标准化组织以及ISO9000和ISO/IEC15504等重要标准体系;在知识产权部分,详细阐述了知识产权的定义、分类及特点,重点分析了计算机软件著作权的主体、客体、权利内容、行使方式、保护期限及侵权认定,同时涉及商业秘密的构成与侵权形式、专利权的类型与申请条件,以及企业如何综合运用著作权、专利、商标和商业秘密等方式保护软件知识产权。; 适合人群:从事软件开发、项目管理、IT标准化或知识产权相关工作的技术人员与管理人员,以及备考相关资格考试的学习者;具备一定信息技术背景,希望系统掌握标准化与软件知识产权基础知识的专业人员。; 使用场景及目标:①帮助理解各类标准的分类体系及国际标准采用方式,提升标准化实践能力;②指导企业在软件研发过程中有效保护知识产权,规避法律风险;③为软件著作权登记、专利申请、技术保密等提供理论依据和操作指引。; 阅读建议:建议结合国家相关政策法规和实际案例进行深入学习,重点关注软件著作权与专利权的适用边界、标准制定流程及企业知识产权管理策略,强化理论与实践的结合。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值