博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU Bag Problem (并非0/1背包)
阅读量:6187 次
发布时间:2019-06-21

本文共 1910 字,大约阅读时间需要 6 分钟。

Bag Problem

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/131072 K (Java/Others)

Total Submission(s): 1011    Accepted Submission(s): 308

Problem Description
0/1 bag problem should sound familiar to everybody. Every earth man knows it well. Here is a mutant: given the capacity of a bag, that is to say, the number of goods the bag can carry (has nothing to do with the volume of the goods), and the weight it can carry. Given the weight of all goods, write a program that can output, under the limit in the above statements, the highest weight.
 

 

Input
Input will consist of multiple test cases The first line will contain two integers n (n<=40) and m, indicating the number of goods and the weight it can carry. Then follows a number k, indicating the number of goods, k <=40. Then k line follows, indicating the weight of each goods The parameters that haven’t been mentioned specifically fall into the range of 1 to 1000000000.
 

 

Output
For each test case, you should output a single number indicating the highest weight that can be put in the bag.
 

 

Sample Input
5 100 8 8 64 17 23 91 32 17 12 5 10 3 99 99 99
 

 

Sample Output
99 0
 

 

Source
 
 
用枚举做的,但是开了两个1<<20的数组来代替1<<41.之后就是一些必要的处理.
 
#include
#include
#include
#include
using namespace std;const int N=50;const int INF=0x3f3f3f3f;struct node{ int weight; int num; void Init(){ weight=0; num=0; }}goodL[1<<20],goodR[1<<20];int goods[N];int start[N/2],end[N/2];int cmp1(node a,node b){ return a.weight==b.weight?a.num
>1; if(goodR[mid].weight==key) return key; if(goodR[mid].weight
>1,r=k-l; for(int i=0;i<(1<
m) break; if(pre==goodL[i].weight) continue; pre=goodL[i].weight; lim=n-goodL[i].num; for(int j=0;j<=min(r,lim);j++){ tmp=Solve(start[j],end[j],m-goodL[i].weight); ans=max(ans,tmp+goodL[i].weight); } } printf("%d\n",ans); } return 0;}

 

转载地址:http://esoda.baihongyu.com/

你可能感兴趣的文章
局部标准差实现对比度增强
查看>>
02、前端基础之CSS
查看>>
同盾科技 & 智能语音 | 你不得不知道的战略布局
查看>>
Java 泛型 <? extends T>和<? super T> 详解
查看>>
mysql进阶(三)31-43
查看>>
Python 多进程实践
查看>>
PostgreSQL之序列(Sequence)
查看>>
nodejs中http连接池复用的问题
查看>>
百度「Web 前端研发部」面试过程和常见问题
查看>>
11g包dbms_parallel_execute在海量数据处理过程中的应用
查看>>
Win7搭建NodeJs开发环境以及HelloWorld展示—图解
查看>>
通过Xshell连接CentOS虚拟机
查看>>
ovirt 平台按照VM,一直卡在seabios
查看>>
Hybris Enterprise Commerce Platform 服务层的设计与实现
查看>>
回收出千亿市场!回收宝获阿里巴巴C1轮战略投资
查看>>
Imperva:2018 Web 应用漏洞数量比 2017 增加了 21%
查看>>
为帝都金三银四准备的Android面试热点题
查看>>
XML教程、语法手册、数据读取方式大全
查看>>
日本借人工智能技术识别早期胃癌
查看>>
maltrieve - 为安全研究人员直接从源头检索恶意软件的工具
查看>>