hdu 1059 多重背包 背包指数分块
思路:
这个方法要看《浅谈几类背包问题》这篇论文。
- #include"stdio.h"
- #define Max(a,b) (a)>(b)?(a):(b)
- int f[],k[];
- int main()
- {
- int i,j,m,Case=;
- while(scanf("%d%d%d%d%d%d",&k[],&k[],&k[],&k[],&k[],&k[])!=EOF,k[]|k[]|k[]|k[]|k[]|k[])
- {
- for(i=;i<=;i++)
- f[i]=;
- int sum=k[]+k[]*+k[]*+k[]*+k[]*+k[]*;
- sum%=;
- int c=sum/;
- if(sum%!=)
- {
- printf("Collection #%d:\nCan't be divided.\n\n",++Case);
- continue;
- }
- for(i=;i<=;i++)
- {
- m=;
- if(k[i]==) continue;
- while(k[i]>)
- {
- if(k[i]<m)
- m=k[i];
- k[i]-=m;
- for(j=c;j>=m*i;j--)
- {
- f[j]=Max(f[j],f[j-m*i]+i*m);
- }
- m*=;
- }
- }
- if(f[c]==c)
- printf("Collection #%d:\nCan be divided.\n\n", ++Case);
- else
- printf("Collection #%d:\nCan't be divided.\n\n",++Case);
- }
- return ;
- }
hdu 1059 多重背包 背包指数分块的更多相关文章
- hdu 1059 (多重背包) Dividing
这里;http://acm.hdu.edu.cn/showproblem.php?pid=1059 题意是有价值分别为1,2,3,4,5,6的商品各若干个,给出每种商品的数量,问是否能够分成价值相等的 ...
- hdu 1059 多重背包
题意:价值分别为1,2,3,4,5,6的物品个数分别为a[1],a[2],a[3],a[4],a[5],a[6],问能不能分成两堆价值相等的. 解法:转化成多重背包 #include<stdio ...
- 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 ...
- HDU 1059 多重背包问题
问题大意: 有价值1-6的六种物品,分别规定其数目,问是否存在一种方法能使这些物品不拆分就能平均分给两个人 #include <cstdio> #include <cstring&g ...
- HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)
HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那 ...
- hdu 1059 Dividing bitset 多重背包
bitset做法 #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a ...
- hdu 5445 多重背包
Food Problem Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)To ...
- HDU 1114 完全背包 HDU 2191 多重背包
HDU 1114 Piggy-Bank 完全背包问题. 想想我们01背包是逆序遍历是为了保证什么? 保证每件物品只有两种状态,取或者不取.那么正序遍历呢? 这不就正好满足完全背包的条件了吗 means ...
- hdu 2546 典型01背包
分析:每种菜仅仅可以购买一次,但是低于5元不可消费,求剩余金额的最小值问题..其实也就是最接近5元(>=5)时, 购买还没有买过的蔡中最大值问题,当然还有一些临界情况 1.当余额充足时,可以随意 ...
随机推荐
- POJ 2031 Building a Space Station (最小生成树)
Building a Space Station 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/C Description Yo ...
- labview 变体数据类型
变体数据类型是LabVIEW中多种数据类型的容器.将其它数据转换为变体时,变体将存储数据和数据的原始类型,保证日后可将变体数据反向转换. 例如,如将字符串数据转换为变体,变体将存储字符串的文本,以及说 ...
- [iOS UI进阶 - 3.2] 手势识别器UIGestureRecognizer
A.系统提供的手势识别器 1.敲击手势 UITapGestureRecognizer numberOfTapsRequired: 敲击次数 numberOfTouchesRequired: 同时敲 ...
- 通过java发送http请求
通常的http请求都是由用户点击某个连接或者按钮来发起的,但是在一些后台的Java程序中需要发送一些get或这post请求,因为不涉及前台页面,该怎么办呢? 下面为大家提供一个Java发送http请求 ...
- 教你50招提升ASP.NET性能(十七):不要认为问题只会从业务层产生
(28)Don’t assume that problems can only arise from business logic 招数28: 不要认为问题只会从业务层产生 When beginnin ...
- The Trip PC/UVa IDs: 110103/10137, Popularity: B, Success rate: average Level: 1
#include<cstdio> #include<iostream> #include<string> #include<algorithm> #in ...
- Unity的使用
1.Ioc功能使用: 1.介绍对象的生命周期 顾名思义 在容器中存在的实例,是可以定义其生命周期的. Unity提供了 几种自带的 生命周期 管理类(常用的已标红) ContainerControll ...
- 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 ...
- CDOJ 486 Good Morning 傻逼题
Good Morning Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/486 ...
- ValueBar
https://github.com/PhilJay/ValueBar