Dividing (hdu 1059 多重背包)
Dividing
1 0 0 0 1 1
0 0 0 0 0 0
Can't be divided.
Can be divided.
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int dp[];
int a[];
int value=;
void completepack(int cost,int weight) //代价cost换取价值weight 完全背包
{
for(int i=cost;i<=value;i++)
dp[i]=max(dp[i],dp[i-cost]+weight);
}
void zeroonepack(int cost,int weight)
{
for(int i=value;i>=cost;i--)
dp[i]=max(dp[i],dp[i-cost]+weight);
}
void multiplepack(int cost,int weight,int amount)
{
int t=;
if(amount*cost>=value)
completepack(cost,weight);
else
{
while(t<amount)
{
zeroonepack(cost*t,cost*t);
amount-=t;
t<<=;
}
if(amount)
zeroonepack(cost*amount,cost*amount);
}
}
int main()
{
int i,j,t=;
freopen("in.txt","r",stdin);
while(scanf("%d%d%d%d%d%d",&a[],&a[],&a[],&a[],&a[],&a[]))
{
int sum=;
for(i=;i<=;i++)
sum+=a[i]*i;
value=sum/;
if(sum==)
break;
printf("Collection #%d:\n",++t);
if(sum%)
{
printf("Can't be divided.\n\n");
continue;
}
memset(dp,,sizeof(dp));
for(i=;i<=;i++)
{
if(a[i])
multiplepack(i,i,a[i]);
}
if(dp[value]==value)
printf("Can be divided.\n\n");
else
printf("Can't be divided.\n\n");
}
return ;
}
Dividing (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 ...
- hdu 1059 多重背包 背包指数分块
思路: 这个方法要看<浅谈几类背包问题>这篇论文. #include"stdio.h" #define Max(a,b) (a)>(b)?(a):(b) ],k[ ...
- hdu 5445 多重背包
Food Problem Time Limit: 3000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)To ...
- HDU 1059 Dividing 分配(多重背包,母函数)
题意: 两个人共同收藏了一些石头,现在要分道扬镳,得分资产了,石头具有不同的收藏价值,分别为1.2.3.4.5.6共6个价钱.问:是否能公平分配? 输入: 每行为一个测试例子,每行包括6个数字,分别对 ...
- ACM学习历程—HDU 1059 Dividing(dp && 多重背包)
Description Marsha and Bill own a collection of marbles. They want to split the collection among the ...
- hdu 2191 多重背包 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
http://acm.hdu.edu.cn/showproblem.php?pid=2191 New~ 欢迎“热爱编程”的高考少年——报考杭州电子科技大学计算机学院关于2015年杭电ACM暑期集训队的 ...
- Big Event in HDU(HDU 1171 多重背包)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1171 Big Event in HDU (多重背包)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
随机推荐
- Absolute sort
Absolute sort Let's try some sorting. Here is an array with the specific rules. The array (a tuple) ...
- 完整的多项匹配tomcat access日志的正则
<pre name="code" class="html"><pre name="code" class="ht ...
- 在Visual Studio Express 2013中开发自定义控件
在专业版本中,新建项目时有"Windows Control Library"这样一个类型可以用于新建自定义控件项目. 但是Express版本中,没有这样一个类型可供选择.这里有另外 ...
- c++ 06
一.下标操作符 A a (...); cout << a[3] << endl; cout << a.operator[] (3) << endl; c ...
- nodejs 设置网络代理
在使用nodejs的过程中,加入使用代理上网,那么安装组件会失败,此时配置代理即可,命令如下: [root@oracle ~]#npm config set proxy=http://10.101.1 ...
- UITableView系列(1)---Apple缓存池机制
一.概述 关于UITableView的基本使用, 其实十分简单.但是做App最重要的之一就是细致,技术方面要做到细致, 必须深入了解底层, 才能做出优化让程序跑得更快.那么这一系列文章从我实际项目中获 ...
- [转] Hive 内置函数
原文见:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF 1.内置运算符1.1关系运算符 运算符 类型 说明 A ...
- poj 2697 A Board Game(bfs+hash)
Description Dao was a simple two-player board game designed by Jeff Pickering and Ben van Buskirk at ...
- js jquery 验证写法
<?php header("Content-type: text/html; charset=utf-8"); ?> <script src="jque ...
- Subsequence(两个单调队列)
Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...