题目意思

有六种不同的石子,权值为\(1\)~\(6\),给出六种石子的数量,求能否将石子分成权值相等的两份.

解析

这题可以直接用多重背包写,

因为仔细想想,

能够平均分成两份,

也就是能将一部分石子拼成总权值的二分之一.

那么,直接用可行性DP写就行了.

(对于可行性DP请自行上百度吧qwq(因为这又是另一个故事了)

上代码吧:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; inline int read(){
int sum=0,f=1;char ch=getchar();
while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0' && ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
return f*sum;
} int a[7],tot=0;
int f[150001],u[150001]; int main(){
while(1){
int sum=0;
for(int i=1;i<=6;i++) a[i]=read(),sum+=a[i]*i;
if(!sum) break;
printf("Collection #%d:\n",++tot);
if(sum%2) {puts("Can't be divided.");puts("");continue;}
memset(f,0,sizeof(f));f[0]=1;
for(int i=1;i<=6;i++){
for(int j=0;j<=sum;j++) u[j]=0;
for(int j=i;j<=sum;j++){
if(!f[j]&&f[j-i]&&u[j-i]<a[i]){
f[j]=1;u[j]=u[j-i]+1;
}
}
}
if(f[sum>>1]) puts("Can be divided.");
else puts("Can't be divided.");
puts("");
}
return 0;
}

题解 【POJ1014】 Dividing的更多相关文章

  1. POJ1014 Dividing

    题目来源:http://poj.org/problem?id=1014 题目大意: Marsha和Bill拥有一些弹珠.但是这些弹珠的价值不一样.每个弹珠的价值都是1到6之间的自然数.他们希望把这些弹 ...

  2. 【DP|多重背包可行性】POJ-1014 Dividing

    Dividing Time Limit: 1000MS Memory Limit: 10000K Description Marsha and Bill own a collection of mar ...

  3. poj1014 Dividing (多重背包)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:id=1014">http://poj.org/problem?id=1014 Descrip ...

  4. POJ1014:Dividing(多重背包)

    http://poj.org/problem?id=1014 Description Marsha and Bill own a collection of marbles. They want to ...

  5. [POJ1014]Dividing(二进制优化多重背包)

    #include <cstdio> #include <algorithm> #include <cstring> using namespace std; int ...

  6. hdu1059&poj1014 Dividing (dp,多重背包的二分优化)

    Problem Description Marsha and Bill own a collection of marbles. They want to split the collection a ...

  7. poj分类解题报告索引

    图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...

  8. 【poj1014】 Dividing

    http://poj.org/problem?id=1014 (题目链接) 题意 给出有分别价值为1,2,3,4,5,6的6种物品,输入6个数字,表示相应价值的物品的数量,问一下能不能将物品分成两份, ...

  9. POJ1014:Dividing

    Dividing Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 63013   Accepted: 16315 Descri ...

随机推荐

  1. Oracle-DQL 3- 单行函数

    单行函数: --使用函数对表中的数据进行运算和处理,针对每行数据返回一个结果,叫做单行函数--包括数字函数,字符函数,日期函数,转换函数,其他函数 1.数字函数 --round(m,n) 将数字m精确 ...

  2. Nginx安装SSL证书,开启HTTPS加密

    效果就是访问博客的时候出现一把小绿锁,更加安(好)全(看). 实现步骤如下: 申请SSL证书 阿里云可以申请一年的免费证书,下载到本地 上传证书到服务器 scp [文件名] root@[ip地址]:/ ...

  3. C++学习 之 程序的组成部分(部分知识笔记)

    1.预处理器编译指令#include: 预处理器是在程序编译前运行的工具.预处理器编译指令是向预处理器发送的命令,总是以#为标识,include便是其中常见的一种,用于引用文件,比如:iostream ...

  4. centos编译安装python3怎么做?

    照着我的博客操作 你一定能成功的!因为我就是一步一步的做出来的,虽然只有文档,但是希望你能有耐心!!!! 编译安装难么麻烦,为什么还要编译安装? 那我告诉你想进步就要折腾!你习惯了windows的安装 ...

  5. Annotation Type ManyToMany->>>>>Oracle

    Example 1: // In Customer class: @ManyToMany @JoinTable(name="CUST_PHONES") public Set< ...

  6. Asp.net core Identity + identity server + angular + odata + 权限管理

    今天踩了一个坑. 网站发布后看到了一个 error Refused to execute inline script because it violates the following Content ...

  7. C语言中signed和unsigned理解

    一直在学java,今天开始研究ACM的算法题,需要用到C语言,发现好多知识点都不清楚了,看来以后要多多总结~ signed意思为有符号的,也就是第一个位代表正负,剩余的代表大小,例如:signed i ...

  8. Android 直连SQL

    在工作中遇到需求需要Android直接连接SQL,看了一些人说不建议直连,但我对性能没有要求,甚至说只要在局域网内能够使用就行,简单说把手机当作一个简单的移动操作点. 代码的话,网上都有比如: htt ...

  9. 客户端注册Cannot execute request on any known server解决

    在对eureka注册中心服务端添加安全验证后,新版本springcloud出现一个问题就是,在客户端注册到服务中心时报了一个错:Cannot execute request on any known ...

  10. HTML学习记录和总结

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明. 作者:struct_mooc 博客地址:https://www.cnblogs.com/stru ...