多重背包 (poj 1014)
题目: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)的更多相关文章
- POJ 1014 Dividing(多重背包+二进制优化)
http://poj.org/problem?id=1014 题意:6个物品,每个物品都有其价值和数量,判断是否能价值平分. 思路: 多重背包.利用二进制来转化成0-1背包求解. #include&l ...
- POJ 1014 Dividing(多重背包)
Dividing Description Marsha and Bill own a collection of marbles. They want to split the collectio ...
- 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 ...
- poj 1014多重背包
题意:给出价值为1,2,3,4,5,6的6种物品数量,问是否能将物品分成两份,使两份的总价值相等. 思路:求出总价值除二,做多重背包,需要二进制优化. 代码: #include<iostream ...
- Dividing POJ - 1014 多重背包二进制优化
多重背包模型 写的时候漏了一个等号找了半天 i<<=1 !!!!!! #include<iostream> #include<cstdio> #include&l ...
- (混合背包 多重背包+完全背包)The Fewest Coins (poj 3260)
http://poj.org/problem?id=3260 Description Farmer John has gone to town to buy some farm supplies. ...
- (多重背包+记录路径)Charlie's Change (poj 1787)
http://poj.org/problem?id=1787 描述 Charlie is a driver of Advanced Cargo Movement, Ltd. Charlie dri ...
- poj 1742 Coins (多重背包)
http://poj.org/problem?id=1742 n个硬币,面值分别是A1...An,对应的数量分别是C1....Cn.用这些硬币组合起来能得到多少种面值不超过m的方案. 多重背包,不过这 ...
- POJ 2392 Space Elevator(贪心+多重背包)
POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num ...
- 【转载】poj 1276 Cash Machine 【凑钱数的问题】【枚举思路 或者 多重背包解决】
转载地址:http://m.blog.csdn.net/blog/u010489766/9229011 题目链接:http://poj.org/problem?id=1276 题意:机器里面共有n种面 ...
随机推荐
- 手把手教你接口自动化测试 – SoapUI & Groovy
手把手教你接口自动化测试 – SoapUI & Groovy http://www.cnblogs.com/wade-xu/p/4236295.html 关键词:SoapUI接口测试,接口自动 ...
- UITapGestureRecognizer响应顺序是怎么样的
一个scrollview上有几个按钮在scrollview上add 了一个单击事件 singletap = [[UITapGestureRecognizer alloc] initWithTarget ...
- ORA-15028: ASM file '..' not dropped; currently being accessed --转载
Couple of weeks ago we had a problem with one of our busiest databases. The FRA was filling quite ra ...
- 使用gson解析,生成Json
包:gson-2.3.jarJson文本解析为Java对象:Java对象生成为Json文本 import com.google.gson.Gson; public class TestGson { c ...
- c# 串口编程
http://news.ccidnet.com/art/32859/20100524/2067861_4.html 字节缓冲器处理类: /// <summary> /// 字节缓冲器 // ...
- maven仓库介绍《本地仓库、远程仓库》
在Maven中,任何一个依赖.插件或者项目构建的输出,都可以称之为构件.Maven在某个统一的位置存储所有项目的共享的构件,这个统一的位置,我们就称之为仓库.(仓库就是存放依赖和插件的地方)任何的构件 ...
- openldap主机访问控制(基于ip)
http://blog.oddbit.com/2013/07/22/generating-a-membero/ http://gsr-linux.blogspot.jp/2011/01/howto-o ...
- dedecms 打印出网站所有 文章标题和链接(URL)的方法
{dede:arclist row="100000"} <li>[field:fulltitle/]***网站URL地址***[field:arcurl/]</l ...
- C# 自定义序列化问题
public class overdue { public int overdueTimes { get; set; } /// <summary ...
- GIM企业即时通讯
GIM企业即时通讯是笔者Garfield(QQ:3674571)采用.NetFramework4.0+SQL2008R2开发的一套企业内网/外网 通用的即时通讯(IM)软件,分为服务器端和客户端,通讯 ...