博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 1059 Dividing
阅读量:7263 次
发布时间:2019-06-29

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

Problem Description
Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had the same value, because then they could just split the collection in half. But unfortunately, some of the marbles are larger, or more beautiful than others. So, Marsha and Bill start by assigning a value, a natural number between one and six, to each marble. Now they want to divide the marbles so that each of them gets the same total value.  
Unfortunately, they realize that it might be impossible to divide the marbles in this way (even if the total value of all marbles is even). For example, if there are one marble of value 1, one of value 3 and two of value 4, then they cannot be split into sets of equal value. So, they ask you to write a program that checks whether there is a fair partition of the marbles.
 

 

Input
Each line in the input describes one collection of marbles to be divided. The lines consist of six non-negative integers n1, n2, ..., n6, where ni is the number of marbles of value i. So, the example from above would be described by the input-line ``1 0 1 2 0 0''. The maximum total number of marbles will be 20000.  
The last line of the input file will be ``0 0 0 0 0 0''; do not process this line.
 

 

Output
For each colletcion, output ``Collection #k:'', where k is the number of the test case, and then either ``Can be divided.'' or ``Can't be divided.''.  
Output a blank line after each test case.
 

 

Sample Input
1 0 1 2 0 0 1 0 0 0 1 1 0 0 0 0 0 0
 

 

Sample Output
Collection #1: Can't be divided. Collection #2: Can be divided.
 

题解:

   第一次写多重背包的问题,其中要考虑是否能被均分,用到物品的价值和所占体积相等,使得判断更加简单。不多说,上代码。

#include 
#include
#include
#include
using namespace std;int dp[120000],V;void bag01(int v,int w) //01背包{ for(int i=V; i>=v; i--) dp[i]=max(dp[i],dp[i-v]+w);}void bag11(int v,int w) //完全背包{ for(int i=v; i<=V; i++) dp[i]=max(dp[i],dp[i-v]+w);}void bagmuti(int m,int v,int w) //多重背包{ if(m*v>=V) bag11(v,w); else { int k=1; while(k

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

你可能感兴趣的文章
Java基础2:基本数据类型与常量池
查看>>
从Web后端(Java)转到游戏服务端的感受
查看>>
设计模式(六)_观察者模式
查看>>
如何优雅地过滤敏感词
查看>>
SELinux初学者指南
查看>>
ECCV 2018 | 旷视科技包揽COCO+Mapillary四项世界第一,中国公司成最大赢家
查看>>
Shiro Ajax请求没有权限返回JSON,没有登录返回JSON
查看>>
classList属性详解
查看>>
MYSQL-锁机制
查看>>
寻找List之和的最近素数
查看>>
程序员必知必会的那些邪恶的脚本
查看>>
Go 程序的基本结构和要素
查看>>
深入理解Java中的反射机制
查看>>
Git命令速查
查看>>
Android--解包、添加文件、打包、签名
查看>>
阿里云服务器ECS操作系统的分类
查看>>
HTML5 manifest离线缓存
查看>>
iframe父子页面通讯解决方案
查看>>
hive外表和事务表
查看>>
人工智能最终将超越人类,但不是反人类
查看>>