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. 请简述一下 Ajax 的原理及实现步骤

    简述 AJAX:AJAX即“Asynchronous Javascript And XML”(异步 JavaScript 和 XML),是指一种创建交互式网页应用的网页开发技术.通过在后台与服务器进行 ...

  2. Spring框架中的依赖注入

    依赖注入(DI : Dependency Injection)是基于.xml配置文件内节点的书写. 注入类型: 1.设置注入,调用了Bean的setXXX()进行值注入 普通属性(value值表示要显 ...

  3. Mysql-5.7 x64安装

    首先在官网下载Mysql:https://dev.mysql.com/downloads/mysql/ 选择ZIP Archive下载. 下载安装之后配置环境变量: 编辑现有环境变量Path: PS: ...

  4. oracle ogg--ogg搭建过程中遇到的错误及处理

    1 PRVF-0002 : Could not retrieve local nodename---# Begin Stacktrace #---------------------------ID: ...

  5. Java ——集合框架 list lambda set map 遍历方法 数据结构

    本节重点思维导图 集合框架 有序无序:元素放入的顺序与取出的顺序是否一致,一致即为有序,不一致即无序. List:允许重复.有序 ArrayList:长度可变的数组,遍历速度快 LinkedList: ...

  6. pycharm运行测试用例遇到错误:ZeroDivisionError: float division by zero的原因

    运行测试用例报错:ZeroDivisionError: float division by zero 一般是因为测试用例模块命名没有以test开头,导致unittest找不到用例,用例总数为0,导致除 ...

  7. bzoj3929 Discrete Logging 大步小步算法

    #include<cstdio> #include<algorithm> #include<cmath> #include<map> using nam ...

  8. bzoj3028食物 关于(1+x+x2+x3+x4+...)^k的第i项系数就是c(i+k−1,k−1)的证明

    关于(1+x+x2+x3+x4+...)^k的第i项系数就是c(i+k−1,k−1)的证明对于第i项,假设为5x^5=x^0*x^5x^5=x^1*x^4x^5=x^2*x^3........也就是说 ...

  9. Pytorch搭建卷积神经网络用于MNIST分类

    import torch from torch.utils.data import DataLoader from torchvision import datasets from torchvisi ...

  10. SpringBoot项目快速启动停止脚本

    SpringBoot项目快速启动停止脚本 1.在jar包同级目录下,创建 app.sh #!/bin/bash appName=`ls|grep .jar$` if [ -z $appName ] t ...