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. Using FileUpload

    Using FileUpload FileUpload can be used in a number of different ways, depending upon the requiremen ...

  2. ps - 按进程消耗内存多少排序

    https://www.cnblogs.com/JemBai/archive/2011/06/21/2086184.html https://www.cnblogs.com/jiqing9006/p/ ...

  3. 二、Python基础

    1.变量名 数字,字母,下划线:aaa1;aa_b1 不能以数字开头:1aa 变量名不能是python内部的关键字 2.getpass import getpass username=raw_inpu ...

  4. Git-Runoob:Git 创建仓库

    ylbtech-Git-Runoob:Git 创建仓库 1.返回顶部 1. Git 创建仓库 本章节我们将为大家介绍如何创建一个 Git 仓库. 你可以使用一个已经存在的目录作为Git仓库. git ...

  5. Jmeter之HTTP常用配置元件(默认、头信息和cookies)

    在进行HTTP接口的测试时,会用到部分常用的配置元件,现在简单的说明: 一.HTTP请求默认值 在测试同一个项目的HTTP请求接口时,会存在部分相同的信息,可以将这些相同的信息提取出来,使用HTTP请 ...

  6. Django开启https(不用nginx)

    首先安装需要用到的包 pip install django-extensions pip install django-werkzeug-debugger-runserver pip install ...

  7. Linux监控命令之==>iostat

    一.使用说明 iostat 是对系统的磁盘I/O 操作进行监控,它的输出主要显示磁盘读写操作的统计信息,同时给出CPU 的使用情况.同vmstat 一样,iostat 不能对某个进程进行深入分析,仅对 ...

  8. HTML——超级链接 表格 框架

  9. 【MM系列】SAP 根据采购订单创建外向交货单的BAPI

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP 根据采购订单创建外向交货单的 ...

  10. AutoML文献阅读

    逐步会更新阅读过的AutoML文献(其实是NAS),以及自己的一些思考 Progressive Neural Architecture Search,2018ECCV的文章: 目的是:Speed up ...