Hdu 1059 Dividing & Zoj 1149 & poj 1014 Dividing(多重背包)
多重背包模板~
#include <stdio.h>
#include <string.h> int a[7];
int f[100005];
int v, k; void ZeroOnePack(int cost, int weight)
{
for (int i = v; i >= cost; i--)
if (f[i - cost] + weight > f[i])
f[i] = f[i - cost] + weight;
}
void CompletePack(int cost, int weight)
{
for (int i = cost; i <= v; i++)
if (f[i - cost] + weight > f[i])
f[i] = f[i - cost] + weight;
}
void MultiplePack(int cost, int weight, int amount)
{
if (cost * amount >= v) CompletePack(cost, weight);
else {
for (int k = 1; k < amount;) {
ZeroOnePack(k * cost, k * weight);
amount -= k;
k <<= 1;
}
ZeroOnePack(amount * cost, amount * weight);
}
} int main()
{
int sum;
int cas = 0;
while (1) {
sum = 0;
for (int i = 1; i < 7; i++) {
scanf("%d", &a[i]);
sum += a[i] * i;
}
if (sum == 0) break;
if (sum % 2 == 1) {
printf("Collection #%d:\nCan't be divided.\n\n", ++cas);
continue;
} else {
v = sum / 2;
memset(f, 0, sizeof(f));
for (int i = 1; i < 7; i++)
MultiplePack(i, i, a[i]);
if (f[v] == v)
printf("Collection #%d:\nCan be divided.\n\n", ++cas);
else
printf("Collection #%d:\nCan't be divided.\n\n", ++cas);
}
}
return 0;
}
Hdu 1059 Dividing & Zoj 1149 & poj 1014 Dividing(多重背包)的更多相关文章
- POJ 1014 Dividing(多重背包)
Dividing Description Marsha and Bill own a collection of marbles. They want to split the collectio ...
- POJ 1014 Dividing(多重背包+二进制优化)
http://poj.org/problem?id=1014 题意:6个物品,每个物品都有其价值和数量,判断是否能价值平分. 思路: 多重背包.利用二进制来转化成0-1背包求解. #include&l ...
- DFS(DP)---POJ 1014(Dividing)
原题目:http://poj.org/problem?id=1014 题目大意: 有分别价值为1,2,3,4,5,6的6种物品,输入6个数字,表示相应价值的物品的数量,问一下能不能将物品分成两份,是两 ...
- Coins(HDU 2844):一个会超时的多重背包
Coins HDU 2844 不能用最基础的多重背包模板:会超时的!!! 之后看了二进制优化了的多重背包. 就是把多重转变成01背包: 具体思路见:http://www.cnblogs.com/tt ...
- POJ 1014 Dividing
Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 66032 Accepted: 17182 Descriptio ...
- POJ 1014 Dividing 多重背包
Dividing Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 63980 Accepted: 16591 Descri ...
- POJ 1014 Dividing (多重可行性背包)
题意 有分别价值为1,2,3,4,5,6的6种物品,输入6个数字,表示相应价值的物品的数量,问一下能不能将物品分成两份,是两份的总价值相等,其中一个物品不能切开,只能分给其中的某一方,当输入六个0是( ...
- POJ 1014 Dividing(多重背包, 倍增优化)
Q: 倍增优化后, 还是有重复的元素, 怎么办 A: 假定重复的元素比较少, 不用考虑 Description Marsha and Bill own a collection of marbles. ...
- POJ 1014 Dividing 背包
二进制优化,事实上是物体的分解问题. 就是比方一个物体有数量限制,比方是13,那么就须要把这个物体分解为1. 2, 4, 6 假设这个物体有数量为25,那么就分解为1, 2, 4. 8. 10 看出规 ...
随机推荐
- maven + selenium + jenkins 教程收集
maven + selenium + jenkins 教程收集 Complete Guide for Selenium integration with jenkins Maven http://le ...
- unicode下各种类型转换,CString,string,char*,int,char[]
把最近用到的各种unicode下类型转换总结了一下,今后遇到其他的再补充: 1.string转CString string a=”abc”; CString str=CString(a.c_str() ...
- 《AngularJS》--指令的相互调用
转载自http://blog.csdn.net/zhoukun1008/article/details/51296692 人们喜欢AngularJS,因为他很有特色,其中他的指令和双向数据绑定很吸引着 ...
- JSP九个隐式对象及作用域
out:JspWriter实例对象,作用域为page(页面执行期) 向客户端输出内容 request:HttpServletRequest实例对象,作用域为request(用户请求期) 请求信息 re ...
- StarUML中时序图添加小人
转载于 http://blog.csdn.net/longyuhome/article/details/9011629 在看时序图的例子的时候,发现有些的时序图上有小人的图标,可是一些UML工具却没有 ...
- linux groupmems命令
Because users group membership is defined in two different locations, it can be difficult to find ou ...
- .bash_profile和.bashrc的区别
参考资料: http://blog.163.com/wang_hai_fei/blog/static/309020312008728333912/
- 读书笔记--用Python写网络爬虫01--网络爬虫简介
Wiki - Web crawler 百度百科 - 网络爬虫 1.1 网络爬虫何时使用 用于快速自动地获取网络信息,避免重复性的手工操作. 1.2 网络爬虫是否合法 网络爬虫目前人处于早期的蛮荒阶段, ...
- 95秀-dialog 进度对话框 实用工具
工具Util public class DialogUtil { public static ProgressDialogView progressDialog; /** * ...
- 国内使用google地图的初级使用
<!DOCTYPE html><html><head><title>Simple Map</title><meta name=&quo ...