link:http://acm.hdu.edu.cn/showproblem.php?pid=1059

最简单的那种

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
const int dir[][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
using namespace std;
int V,m[],c[],w[],f[];
void zeropack(int c, int w)
{
for (int v=V;v>=c;--v) f[v]=max(f[v],f[v-c]+w);
return;
}
void completepack(int c,int w)
{
for(int v=c;v<=V;++v) f[v]=max(f[v],f[v-c]+w);
return;
}
void multipack(int c,int w,int m)
{
if(c*m>=V)
{
completepack(c,w); return;
}
int k=;
while (k<m)
{
zeropack(k*c,k*w); m-=k; k*=;
}
zeropack(c*m,w*m);
return;
}
int main(void)
{
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif // ONLINE_JUDGE
int t=; for(int i=;i<;++i) c[i]=w[i]=i+;
while ()
{
int sum=;
for(int i=;i<;++i) cin>>m[i], sum+=m[i]*(i+);
if(!sum) break;
// if(t!=1) cout<<endl;
cout<< "Collection #"<<t<<":\n";
t++;
if(sum&) {cout<< "Can't be divided."<<endl<<endl; continue;}
V=sum/;
memset(f,-INF,sizeof(f)); f[]=;
for(int i=;i<;++i) multipack(c[i],w[i],m[i]);
if(f[V]<) cout<< "Can't be divided."<<endl;
else cout<< "Can be divided."<<endl;
cout<<endl;
}
return ;
}

其实还是要理解一下这个思想……
不能单靠记忆

hdu1059 Dividing ——多重背包的更多相关文章

  1. poj1014 hdu1059 Dividing 多重背包

    有价值为1~6的宝物各num[i]个,求能否分成价值相等的两部分. #include <iostream> #include <cstring> #include <st ...

  2. hdu1059 dp(多重背包二进制优化)

    hdu1059 题意,现在有价值为1.2.3.4.5.6的石头若干块,块数已知,问能否将这些石头分成两堆,且两堆价值相等. 很显然,愚蠢的我一开始并想不到什么多重背包二进制优化```因为我连听都没有听 ...

  3. hdu 1059 Dividing(多重背包优化)

    Dividing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

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

  5. hdu-1059(多重背包+二进制优化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1059 题意:输入6个数,每个数ni代表价值为i的物品有ni个.求如果这些物品能均分给两个人,每个人获得 ...

  6. hdu 1059 Dividing 多重背包

    点击打开链接链接 Dividing Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  7. Dividing 多重背包 倍增DP

    Dividing 给出n个物品的价值和数量,问是否能够平分.

  8. POJ 1014 Dividing 多重背包

    Dividing Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 63980   Accepted: 16591 Descri ...

  9. POJ 1014 Dividing(多重背包, 倍增优化)

    Q: 倍增优化后, 还是有重复的元素, 怎么办 A: 假定重复的元素比较少, 不用考虑 Description Marsha and Bill own a collection of marbles. ...

随机推荐

  1. getBoundingClientRect() 来获取页面元素的位置

    getBoundingClientRect() 来获取页面元素的位置   document.documentElement.getBoundingClientRect 下面这是MSDN的解释: Syn ...

  2. [C/C++]C++标准

    本文若如特别说明都引于ISO/IEC 14882:2011 7.声明(Declarations) 声明序列(declaration-seq):    声明(declaration)    声明序列(d ...

  3. 2013年9月份第1周51Aspx源码发布详情

    大型B2B家具门户网源码  2013-9-6 [VS2008]功能描述: 1.门户信息管理 安全取数据即使数据库连接中断不会报错 2.稳定性 每句代码经过3次以上检查.此网站还在运营3年了,没有出过问 ...

  4. C# 展开和折叠代码的快捷键(总结)

    C# 展开和折叠代码的快捷键 VS2005代码编辑器的展开和折叠代码确实很方便和实用.以下是展开代码和折叠代码所用到的快捷键,很常用: Ctrl + M + O: 折叠所有方法 Ctrl + M +  ...

  5. ubuntu16.04操作练习&问题解决

    1. 安装更新时提示/boot空间不足: boot文件夹里存放的是系统引导文件和内核的一些东西,旧内核的东西需要手动删除,释放空间.所以: step1:查看 dpkg --get-selections ...

  6. javascript正则表达式替换字符串

    var reg = /^per_list(.*)[\d]{1,}(.*)/;var str = "per_listAmtApril1.value";var replaceStr = ...

  7. 实现:编辑短信,按power键锁屏后,再点亮屏幕,进入的还是编辑短信界面,按返回键才会进入解锁界面。

    描述:在编辑短信界面按电源键锁屏后,重新按电源键点亮屏幕,并没有进入到锁屏界面而是在编辑短信界面,此时短信界面悬浮与锁屏界面之上,这时按返回键关闭编辑短信界面,回到锁屏界面,是如何实现的呢,只需要在需 ...

  8. windows socket网络编程基础知识

    下面介绍网络7层协议在WINDOWS的实现: 7层协议 WIN系统 ________________________________________ 7 应用层 7 应用程序 ____________ ...

  9. 【LeetCode OJ】Word Break II

    Problem link: http://oj.leetcode.com/problems/word-break-ii/ This problem is some extension of the w ...

  10. IndexOf() LastIndexOf() Contains() StartsWith() EndsWith()方法比较

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...