题目意思

有六种不同的石子,权值为\(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. DAO语句如何定义属性类型

    字体设置:代码 14px 文字 幼圆 15px public interface IAddressDAO { //添加地址 public boolean doCreate(Address addres ...

  2. 状压DP--Rotate Columns (hard version)-- Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

    题意:https://codeforc.es/problemset/problem/1209/E2 给你一个n(1-12)行m(1-2000)列的矩阵,每一列都可以上下循环移动(类似密码锁). 问你移 ...

  3. Symfony4框架中单元测试和接口测试中的一些小坑

    前提说明: symfony 版本 4.1.*,使用  composer create-project symfony/website-skeleton  进行安装. 目标:在一个单元测试用例中对当前工 ...

  4. 数据库连接池的sqlhelper

    import pymysql import threading from DBUtils.PooledDB import PooledDB """ storage = { ...

  5. 对CSRF(跨站请求伪造)的理解

    一.什么是CSRF? CSRF是Cross Site Request Forgery的缩写,翻译过来就是跨站请求伪造.那么什么是跨站请求伪造呢?让我一个词一个词的解释: 1.跨站:顾名思义,就是从一个 ...

  6. pb datawindow 类型

    DataWindow.Processing 判断 DataWindow 对象的类型 可用 DataWindow.Processing 判断 DataWindow 对象的类型,dw的类型如下:     ...

  7. Qt5.8.0编译QtMqtt库并使用该库连接有人云的例子

    一 编译QtMqtt库Qt5.10才官方支持MQTT,但我用的Qt版本是5.8.0 Mingw_32BIT, 为了在Qt5.8.0上添加MQTT支持,需要自己编译源码 步骤: (1) git clon ...

  8. C++中重载函数详解

    函数的重载详解 什么时函数重载: 函数重载是指在同一作用域内,可以有一组具有相同函数名,不同参数列表的函数,这组函数被称为重载函数.重载函数通常用来命名一组功能相似的函数,这样做减少了函数名的数量,避 ...

  9. (转载)项目中表、类、包、JSP命名规范

    对于Java(包括在jsp中)的代码,类名一律用pascal标记法,每个单词的头个字母大写:参数,方法一律用camel标记法,首字母是小写的,能不缩写的都不缩写! 项目名 = 数据库名         ...

  10. 解决maven依赖包下载慢的问题

    修改maven 目录下setting.xml配置文件 在mirrors中添加如下配置即可 <mirror> <id>alimaven</id> <name&g ...