题目:Dividing

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

 

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <cmath>
  6. #include <cstdio>
  7. #include <string>
  8. #include <cstring>
  9. #include <vector>
  10. #include <queue>
  11. #include <stack>
  12. #include <set>
  13.  
  14. #define c_false ios_base::sync_with_stdio(false); cin.tie(0)
  15. #define INF 0x3f3f3f3f
  16. #define INFL 0x3f3f3f3f3f3f3f3f
  17. #define zero_(x,y) memset(x , y , sizeof(x))
  18. #define zero(x) memset(x , 0 , sizeof(x))
  19. #define MAX(x) memset(x , 0x3f ,sizeof(x))
  20. #define swa(x,y) {LL s;s=x;x=y;y=s;}
  21. using namespace std ;
  22. #define N 20005
  23.  
  24. const double PI = acos(-1.0);
  25. typedef long long LL ;
  26. int dp[*N];
  27. int i = ;
  28. int W,a[];
  29. void ZeroOnePack(int siz, int prise){
  30. for(int i = W;i>=siz;i--)
  31. dp[i] = max(dp[i], dp[i-siz] + prise);
  32. }
  33.  
  34. void CompletePack(int siz, int prise){
  35. for(int i = siz; i<= W; i++)
  36. dp[i] = max(dp[i], dp[i-siz]+prise);
  37. }
  38.  
  39. void MultiplePack(int siz, int prise, int num){
  40. if(siz*num >= W){
  41. CompletePack(siz,prise);
  42. return ;
  43. }
  44. int k = ;
  45. while(k<num){
  46. ZeroOnePack(k*siz, k*prise);
  47. num-=k;
  48. k*=;
  49. }
  50. ZeroOnePack(num*siz, num*prise);
  51. }
  52.  
  53. bool cal(){
  54. if(W% == ) W/=;
  55. else return false;
  56. for(int i = ; i <= ; i++ ){
  57. MultiplePack(i,i,a[i]);
  58. }
  59. if(dp[W] == W)
  60. return true;
  61. else
  62. return false;
  63. }
  64.  
  65. int main(void){
  66. //freopen("in.txt","r",stdin);
  67. while(cin>>a[]>>a[]>>a[]>>a[]>>a[]>>a[]){
  68. zero(dp);
  69. W = ;
  70. for(int j = ;j <= ;j++){
  71. W+=j*a[j];
  72. }
  73. if(a[]== &&a[] == &&a[] == && a[] == && a[] ==&& a[] ==)
  74. break;
  75. printf("Collection #%d:\n",++i);
  76. if(cal())
  77. puts("Can be divided.\n");
  78. else
  79. puts("Can't be divided.\n");
  80. }
  81. return ;
  82. }

多重背包 (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. 手把手教你接口自动化测试 – SoapUI & Groovy

    手把手教你接口自动化测试 – SoapUI & Groovy http://www.cnblogs.com/wade-xu/p/4236295.html 关键词:SoapUI接口测试,接口自动 ...

  2. UITapGestureRecognizer响应顺序是怎么样的

    一个scrollview上有几个按钮在scrollview上add 了一个单击事件 singletap = [[UITapGestureRecognizer alloc] initWithTarget ...

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

  4. 使用gson解析,生成Json

    包:gson-2.3.jarJson文本解析为Java对象:Java对象生成为Json文本 import com.google.gson.Gson; public class TestGson { c ...

  5. c# 串口编程

    http://news.ccidnet.com/art/32859/20100524/2067861_4.html 字节缓冲器处理类: /// <summary> /// 字节缓冲器 // ...

  6. maven仓库介绍《本地仓库、远程仓库》

    在Maven中,任何一个依赖.插件或者项目构建的输出,都可以称之为构件.Maven在某个统一的位置存储所有项目的共享的构件,这个统一的位置,我们就称之为仓库.(仓库就是存放依赖和插件的地方)任何的构件 ...

  7. openldap主机访问控制(基于ip)

    http://blog.oddbit.com/2013/07/22/generating-a-membero/ http://gsr-linux.blogspot.jp/2011/01/howto-o ...

  8. dedecms 打印出网站所有 文章标题和链接(URL)的方法

    {dede:arclist row="100000"} <li>[field:fulltitle/]***网站URL地址***[field:arcurl/]</l ...

  9. C# 自定义序列化问题

        public class overdue     {         public int overdueTimes { get; set; }         /// <summary ...

  10. GIM企业即时通讯

    GIM企业即时通讯是笔者Garfield(QQ:3674571)采用.NetFramework4.0+SQL2008R2开发的一套企业内网/外网 通用的即时通讯(IM)软件,分为服务器端和客户端,通讯 ...