题目: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. CRM合并事件

    1 Only account, contact, lead, incident entities are supported for merge 2 Merging Custom Entity Rec ...

  2. pytion学习1

    个人感觉学习一门新语言,简单的语法懂一点足矣.接下来就是编程.读懂别人程序的每一句,理解每一句的意义. #Filename:MyAddressBook.py import cPickle as p i ...

  3. php curl vs python提交多维数组+文件

    总结: 1.data数据格式 2.php post 格式无需json_encode(关联数组,所以可以绕弯)  参考:http://bbs.csdn.net/topics/390645553?page ...

  4. java.lang.UnsupportedClassVersionError

    尝试运行出错,出错原因:/tmp/tmp_1458557049226652 exit 1, Exception in thread "main" java.lang.Unsuppo ...

  5. 移动设备页面高度不足时min-height 的尴尬处理

    移动设备页面高度不足时min-height 的尴尬处理 在做html5的页面时,经常遇到页面内容太少撑不起来整个手机屏幕的高度. 我们经常使用min-height来处理,比如min-height:56 ...

  6. JavaScript 对象 之创建对象 学习笔记

    假设我们有这样的一个需求:记录一个人的 名字和年龄,然后有个方法可以显示这个人的名字和年龄. 按照普通的方法,我们的代码应该是这样的: var person1 = new Object() , per ...

  7. C# WinForm 单例模式(例:同一个窗体只创建一次实例)

    //C# WinForm 单例模式(例:同一个窗体只创建一次实例) //打开窗体的事件: Form3 f = Form3.InstanceObject() ; //实例化窗体 f.Focus(); / ...

  8. 记录今天学习python中for与while循环针对break和continue的用法

    python中有两个主要的循环for与while,其中针对这两个循环有两种不同的中断用法break与continue. 首先先看下面的循环代码: 1: for i in range(10):#变量i带 ...

  9. VC++ MFC 按钮的全部样式Style

    Button Styles BS_3STATE 与复选框一样本样式按钮可被单击变暗.变暗状态通常用于指示本样式的按键正处于禁用状态. BS_AUTO3STATE   与三状态的复选框一样当用户选中它本 ...

  10. HTML DOM appendChild() 方法

    <!DOCTYPE html> <html> <body> <ul id="myList"> <li>Coffee< ...