思路:

这个方法要看《浅谈几类背包问题》这篇论文。

  1. #include"stdio.h"
  2. #define Max(a,b) (a)>(b)?(a):(b)
  3. int f[],k[];
  4. int main()
  5. {
  6. int i,j,m,Case=;
  7. while(scanf("%d%d%d%d%d%d",&k[],&k[],&k[],&k[],&k[],&k[])!=EOF,k[]|k[]|k[]|k[]|k[]|k[])
  8. {
  9. for(i=;i<=;i++)
  10. f[i]=;
  11. int sum=k[]+k[]*+k[]*+k[]*+k[]*+k[]*;
  12. sum%=;
  13. int c=sum/;
  14. if(sum%!=)
  15. {
  16. printf("Collection #%d:\nCan't be divided.\n\n",++Case);
  17. continue;
  18. }
  19. for(i=;i<=;i++)
  20. {
  21. m=;
  22. if(k[i]==) continue;
  23. while(k[i]>)
  24. {
  25. if(k[i]<m)
  26. m=k[i];
  27. k[i]-=m;
  28. for(j=c;j>=m*i;j--)
  29. {
  30. f[j]=Max(f[j],f[j-m*i]+i*m);
  31. }
  32. m*=;
  33. }
  34. }
  35. if(f[c]==c)
  36. printf("Collection #%d:\nCan be divided.\n\n", ++Case);
  37. else
  38. printf("Collection #%d:\nCan't be divided.\n\n",++Case);
  39. }
  40. return ;
  41. }

hdu 1059 多重背包 背包指数分块的更多相关文章

  1. hdu 1059 (多重背包) Dividing

    这里;http://acm.hdu.edu.cn/showproblem.php?pid=1059 题意是有价值分别为1,2,3,4,5,6的商品各若干个,给出每种商品的数量,问是否能够分成价值相等的 ...

  2. hdu 1059 多重背包

    题意:价值分别为1,2,3,4,5,6的物品个数分别为a[1],a[2],a[3],a[4],a[5],a[6],问能不能分成两堆价值相等的. 解法:转化成多重背包 #include<stdio ...

  3. Dividing (hdu 1059 多重背包)

    Dividing Sample Input 1 0 1 2 0 0 价值为1,2,3,4,5,6的物品数目分别为 1 0 1 2 0 0,求能否将这些物品按价值分为两堆,转化为多重背包.1 0 0 0 ...

  4. HDU 1059 多重背包问题

    问题大意: 有价值1-6的六种物品,分别规定其数目,问是否存在一种方法能使这些物品不拆分就能平均分给两个人 #include <cstdio> #include <cstring&g ...

  5. HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)

    HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那 ...

  6. hdu 1059 Dividing bitset 多重背包

    bitset做法 #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a ...

  7. hdu 5445 多重背包

    Food Problem Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)To ...

  8. HDU 1114 完全背包 HDU 2191 多重背包

    HDU 1114 Piggy-Bank 完全背包问题. 想想我们01背包是逆序遍历是为了保证什么? 保证每件物品只有两种状态,取或者不取.那么正序遍历呢? 这不就正好满足完全背包的条件了吗 means ...

  9. hdu 2546 典型01背包

    分析:每种菜仅仅可以购买一次,但是低于5元不可消费,求剩余金额的最小值问题..其实也就是最接近5元(>=5)时, 购买还没有买过的蔡中最大值问题,当然还有一些临界情况 1.当余额充足时,可以随意 ...

随机推荐

  1. POJ 2031 Building a Space Station (最小生成树)

    Building a Space Station 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/C Description Yo ...

  2. labview 变体数据类型

    变体数据类型是LabVIEW中多种数据类型的容器.将其它数据转换为变体时,变体将存储数据和数据的原始类型,保证日后可将变体数据反向转换. 例如,如将字符串数据转换为变体,变体将存储字符串的文本,以及说 ...

  3. [iOS UI进阶 - 3.2] 手势识别器UIGestureRecognizer

    A.系统提供的手势识别器   1.敲击手势 UITapGestureRecognizer numberOfTapsRequired: 敲击次数 numberOfTouchesRequired: 同时敲 ...

  4. 通过java发送http请求

    通常的http请求都是由用户点击某个连接或者按钮来发起的,但是在一些后台的Java程序中需要发送一些get或这post请求,因为不涉及前台页面,该怎么办呢? 下面为大家提供一个Java发送http请求 ...

  5. 教你50招提升ASP.NET性能(十七):不要认为问题只会从业务层产生

    (28)Don’t assume that problems can only arise from business logic 招数28: 不要认为问题只会从业务层产生 When beginnin ...

  6. The Trip PC/UVa IDs: 110103/10137, Popularity: B, Success rate: average Level: 1

    #include<cstdio> #include<iostream> #include<string> #include<algorithm> #in ...

  7. Unity的使用

    1.Ioc功能使用: 1.介绍对象的生命周期 顾名思义 在容器中存在的实例,是可以定义其生命周期的. Unity提供了 几种自带的 生命周期 管理类(常用的已标红) ContainerControll ...

  8. Codeforces Round #333 (Div. 1) C. Kleofáš and the n-thlon 树状数组优化dp

    C. Kleofáš and the n-thlon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...

  9. CDOJ 486 Good Morning 傻逼题

    Good Morning Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/486 ...

  10. ValueBar

    https://github.com/PhilJay/ValueBar