题目:Dividing

 题意:6种重量的的石头,每个给定数量,用总重的一半去装,问能否装满.

 

#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set> #define c_false ios_base::sync_with_stdio(false); cin.tie(0)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define zero_(x,y) memset(x , y , sizeof(x))
#define zero(x) memset(x , 0 , sizeof(x))
#define MAX(x) memset(x , 0x3f ,sizeof(x))
#define swa(x,y) {LL s;s=x;x=y;y=s;}
using namespace std ;
#define N 20005 const double PI = acos(-1.0);
typedef long long LL ;
int dp[*N];
int i = ;
int W,a[];
void ZeroOnePack(int siz, int prise){
for(int i = W;i>=siz;i--)
dp[i] = max(dp[i], dp[i-siz] + prise);
} void CompletePack(int siz, int prise){
for(int i = siz; i<= W; i++)
dp[i] = max(dp[i], dp[i-siz]+prise);
} void MultiplePack(int siz, int prise, int num){
if(siz*num >= W){
CompletePack(siz,prise);
return ;
}
int k = ;
while(k<num){
ZeroOnePack(k*siz, k*prise);
num-=k;
k*=;
}
ZeroOnePack(num*siz, num*prise);
} bool cal(){
if(W% == ) W/=;
else return false;
for(int i = ; i <= ; i++ ){
MultiplePack(i,i,a[i]);
}
if(dp[W] == W)
return true;
else
return false;
} int main(void){
//freopen("in.txt","r",stdin);
while(cin>>a[]>>a[]>>a[]>>a[]>>a[]>>a[]){
zero(dp);
W = ;
for(int j = ;j <= ;j++){
W+=j*a[j];
}
if(a[]== &&a[] == &&a[] == && a[] == && a[] ==&& a[] ==)
break;
printf("Collection #%d:\n",++i);
if(cal())
puts("Can be divided.\n");
else
puts("Can't be divided.\n");
}
return ;
}

多重背包 (poj 1014)的更多相关文章

  1. POJ 1014 Dividing(多重背包+二进制优化)

    http://poj.org/problem?id=1014 题意:6个物品,每个物品都有其价值和数量,判断是否能价值平分. 思路: 多重背包.利用二进制来转化成0-1背包求解. #include&l ...

  2. POJ 1014 Dividing(多重背包)

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

  3. 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 ...

  4. poj 1014多重背包

    题意:给出价值为1,2,3,4,5,6的6种物品数量,问是否能将物品分成两份,使两份的总价值相等. 思路:求出总价值除二,做多重背包,需要二进制优化. 代码: #include<iostream ...

  5. Dividing POJ - 1014 多重背包二进制优化

    多重背包模型  写的时候漏了一个等号找了半天 i<<=1 !!!!!! #include<iostream> #include<cstdio> #include&l ...

  6. (混合背包 多重背包+完全背包)The Fewest Coins (poj 3260)

    http://poj.org/problem?id=3260   Description Farmer John has gone to town to buy some farm supplies. ...

  7. (多重背包+记录路径)Charlie's Change (poj 1787)

    http://poj.org/problem?id=1787   描述 Charlie is a driver of Advanced Cargo Movement, Ltd. Charlie dri ...

  8. poj 1742 Coins (多重背包)

    http://poj.org/problem?id=1742 n个硬币,面值分别是A1...An,对应的数量分别是C1....Cn.用这些硬币组合起来能得到多少种面值不超过m的方案. 多重背包,不过这 ...

  9. POJ 2392 Space Elevator(贪心+多重背包)

    POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num ...

  10. 【转载】poj 1276 Cash Machine 【凑钱数的问题】【枚举思路 或者 多重背包解决】

    转载地址:http://m.blog.csdn.net/blog/u010489766/9229011 题目链接:http://poj.org/problem?id=1276 题意:机器里面共有n种面 ...

随机推荐

  1. Aspose.Cells 设置背景颜色

    很多小伙伴设置背景颜色都不起作用,特别提醒需要加入下面一行: style.Pattern = BackgroundType.Solid; Aspose.Cells.Style style = null ...

  2. 转:Oracle表分区

    Oracle表分区分为四种:范围分区,散列分区,列表分区和复合分区. 一:范围分区 就是根据数据库表中某一字段的值的范围来划分分区,例如: 1. create table graderecord 2. ...

  3. JavaScript(Iframe、window.open、window.showModalDialog)父窗口与子窗口之间的操作

    一.Iframe 篇 公共部分 //父对象得到子窗口的值 //ObjectID是窗口标识,ContentID是元素ID function GetValue(ObjectID,ContentID) { ...

  4. Qlik 函数说明

    集合表达式 包括 标识符 标识符 说明 1 表示应用程序中所有记录的完整集合,而不考虑选择的任何选择项.考虑维度 $ 表示当前选择项的记录.因此,集合表达式 {$} 与不陈述集合表达式的意义等同. $ ...

  5. MSsql bcp

    --将test_1表导出在F盘根目录下/ reconfigure EXEC master..xp_cmdshell 'bcp test.dbo.test_1 out f:\abc.txt -c -q ...

  6. 【转载】Fast Inserts to PostgreSQL with JDBC and COPY FROM

    source: http://rostislav-matl.blogspot.com/2011/08/fast-inserts-to-postgresql-with-jdbc.html Thanks ...

  7. jquery源码学习之queue方法

    队列模块的代码结构 静态方法jQuery下有queue,dequeue,_queueHooks这三种方法:静态方法不建议直接在外部调用: 实例方法.queue,.dequeue,.clearQueue ...

  8. IIS7中配置FastCGI运行PHP

    环境说明: 操作系统:使用windows 2008 server 64位系统,IIS7.5PHP版本:官方下载PHP 5.4.16 VC9 x86 Non Thread SafeZIP版本.PHP路径 ...

  9. 《算法设计手册》面试题解答 第五章:图的遍历 附:DFS应用之找挂接点

    第五章面试题解答 5-31. DFS和BFS使用了哪些数据结构? 解析: 其实刚读完这一章,我一开始想到的是用邻接表来表示图,但其实用邻接矩阵也能实现啊?后来才发现应该回答,BFS用队列实现:DFS可 ...

  10. Redis 的Lua Script脚本功能

    从 Redis 2.6.0 版本开始,通过内置的 Lua 解释器,可以使用 EVAL 命令对 Lua 脚本进行求值 Redis2.6内置的Lua Script支持,可以在Redis的Server端一次 ...