bitset做法

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
const double EPS = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 2e5 + ;
const int maxm = ;
//next_permutation
//priority_queue<int, vector<int>, greater<int>> que;
int num[];
bitset<>f;
int main()
{
//freopen("bonuses.in", "r", stdin);
//freopen("out.txt", "w", stdout);
int t = ;
int sum = ;
//cin >> t;
while (cin >> num[] >> num[] >> num[] >> num[] >> num[] >> num[] && (num[] + num[] + num[] + num[] + num[] + num[]))
{
t++;
cout<<"Collection #"<<t<<":"<<endl;
sum = ;
f.reset();
f[] = ;
for (int i = ; i <= ; i++)
{
sum += num[i] * i;
}
if (sum % )
{
cout << "Can't be divided." << endl;
}
else
{
sum /= ;
for (int i = ; i <= ; i++)
{
int g = ;
int v = i;
int tot = num[i];
while (tot)
{
f |= f << v;
tot -= g;
g = min(g * , tot);
v = g * i;
}
}
if (f[sum])
{
cout << "Can be divided." << endl;
}
else
{
cout << "Can't be divided." << endl;
}
//for(int i=1;i<=sum;i++)
//cout<<f[i]<<" ";
//cout<<endl;
}
cout<<endl;
} }

多重板子做法

//多重背包
//HDU 1059
//题意:价值分别为1,2,3,4,5,6的物品的个数分别为 a[1],a[2],````a[6]
//问能不能分成两堆价值相等的 #include<stdio.h>
#include<string.h>
int a[];
int f[];
int v,k;
void ZeroOnePack(int cost,int weight)//cost 为费用, weight 为价值
{
for(int i=v;i>=cost;i--)
if(f[i-cost]+weight>f[i]) f[i]=f[i-cost]+weight;
}
void CompletePack(int cost,int weight)
{
for(int i=cost;i<=v;i++)
if(f[i-cost]+weight>f[i]) f[i]=f[i-cost]+weight;
}
void MultiplePack(int cost ,int weight,int amount)
{
if(cost*amount>=v) CompletePack(cost,weight);
else
{
for(int k=;k<amount;)
{
ZeroOnePack(k*cost,k*weight);
amount-=k;
k<<=;
}
ZeroOnePack(amount*cost,amount*weight);
}
}
int main()
{
int tol;
int iCase=;
while()
{
iCase++;
tol=;
for(int i=;i<;i++)
{
scanf("%d",&a[i]);
tol+=a[i]*i;//总价值数
}
if(tol==) break;
if(tol%==)
{
printf("Collection #%d:\nCan't be divided.\n\n",iCase);
continue;
}
else
{
v=tol/;
memset(f,,sizeof(f));
for(int i=;i<;i++)
MultiplePack(i,i,a[i]);
if(f[v]==v)
printf("Collection #%d:\nCan be divided.\n\n",iCase);
else printf("Collection #%d:\nCan't be divided.\n\n",iCase);
}
}
return ;
}

hdu 1059 Dividing bitset 多重背包的更多相关文章

  1. HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)

    HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那 ...

  2. 题解报告:hdu 1059 Dividing(多重背包、多重部分和问题)

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

  3. HDU 1059 Dividing(多重背包)

    点我看题目 题意: 将大理石的重量分为六个等级,每个等级所在的数字代表这个等级的大理石的数量,如果是0说明这个重量的大理石没有.将其按重量分成两份,看能否分成. 思路 :一开始以为是简单的01背包,结 ...

  4. HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)

    HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...

  5. HDU 1059 Dividing 分配(多重背包,母函数)

    题意: 两个人共同收藏了一些石头,现在要分道扬镳,得分资产了,石头具有不同的收藏价值,分别为1.2.3.4.5.6共6个价钱.问:是否能公平分配? 输入: 每行为一个测试例子,每行包括6个数字,分别对 ...

  6. hdu 1059 Dividing(多重背包优化)

    Dividing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  7. Hdu 1059 Dividing & Zoj 1149 & poj 1014 Dividing(多重背包)

    多重背包模板- #include <stdio.h> #include <string.h> int a[7]; int f[100005]; int v, k; void Z ...

  8. ACM学习历程—HDU 1059 Dividing(dp && 多重背包)

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

  9. POJ 1014 Dividing(多重背包)

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

随机推荐

  1. Route53 health check与 Cloudwatch alarm 没法绑定

    原因 即使在控制台创建 创建的alarm会在us-east-1 不会再其他区域,目前route53 metric 在其他区域不存在. 所以使用cloudformation 创建 route53 hea ...

  2. 基于EasyHook实现监控explorer资源管理器文件复制、删除、剪切等操作

    一.前言 最近自己在研究一个项目,需要实现对explorer资源管理器文件操作的监控功能,网上找到一些通过C++实现Hook explorer文件操作的方法,由于本人习惯用.NET开发程序,加之C/C ...

  3. 139、TensorFlow Serving 实现模型的部署(二) TextCnn文本分类模型

    昨晚终于实现了Tensorflow模型的部署 使用TensorFlow Serving 1.使用Docker 获取Tensorflow Serving的镜像,Docker在国内的需要将镜像的Repos ...

  4. Java ——异常处理

    本节重点思维导图 详细戳——> 异常处理

  5. linux系统高级命令进阶

    输出重定向 >:覆盖文件内容 echo "123" > test:把原来的内容覆盖 echo "123" >> test:把原来的存在( ...

  6. finereport连接mysql8.0的解决办法

    1.具体连接操作 首先将mysql-connector-java-8.0以上的jar包放到FindReport安装目录下的webapps下的WEB-INF下的lib下. 打开finereport,找到 ...

  7. 【Linux开发】Linux启动脚本设置

    前言linux有自己一套完整的启动 体系,抓住了linux启动 的脉络,linux的启动 过程将不再神秘.阅读之前建议先看一下附图.本文中假设inittab中设置的init tree为:/etc/rc ...

  8. linux/linux学习笔记-初识linux(mooc)

    一.linux简介 linux版本:内核版本和发行版本 linux企业应用: 1.基于linux的企业服务器 2.linux在嵌入式领域应用 android底层Linux : ios底层unix li ...

  9. git自动上传脚本及基本代码

    git_auto.bat git add . git add -A git add -u git commit -m "text" git pull --rebase origin ...

  10. 第六周学习总结&(实验报告四)

    一.实验目的 (1)掌握类的继承方法 (2)变量的继承和覆盖,方法的继承,重载和覆盖实现 二.实验内容 一.实验目的 (1)掌握类的继承 (2)变量的继承和覆盖,方法的继承,重载和覆盖的实现: 二.实 ...