hdu 1059 Dividing(完全背包)
2015-07-16 09:01
260 查看
[code]/* *********************************************** Author :xryz Email :xiang578@foxmail.com Created Time :2015/7/16 8:29:33 File Name :C:\Users\Administrator\Desktop\0001.cpp ************************************************ */ #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; int sum,v,dp[50000]; void zeroonepack(int cost,int weight) { for(int i=v; i>=cost; i--) { dp[i]=max(dp[i],dp[i-cost]+weight); } } void completepack(int cost ,int weight) { for(int i=cost; i<=v; i++) { dp[i]=max(dp[i],dp[i-cost]+weight); } } void multiplepack(int cost ,int weight,int amount) { if(cost*amount>=v) { completepack(cost,weight); } else { int k=1; while(k<amount) { zeroonepack(cost*k,weight*k); amount-=k; k*=2; } zeroonepack(cost*amount,weight*amount); } } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int _=0,a[10],i; while(~scanf("%d%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5],&a[6])) { if(a[1]==0&&a[2]==0&&a[3]==0&&a[4]==0&&a[5]==0&&a[6]==0) break; sum=0; for(i=1; i<=6; i++) sum+=i*a[i]; v=sum/2; memset(dp,0,sizeof(dp)); for(i=1; i<=6; i++) { multiplepack(i,i,a[i]); } printf("Collection #%d:\n",++_); if(sum==2*dp[v]) printf("Can be divided.\n\n"); else printf("Can't be divided.\n\n"); } return 0; }
相关文章推荐
- LNOI2013最小距离之和题解
- c++前置声明
- setwindowstext
- scrollView顶部空白
- hdu 1059 Dividing(完全背包)
- 一个程序员的顿悟
- 微信企业号开发:获取数据权限错误如何处理
- 折半查找
- Error when loading the SDK:解决方案
- 曼哈顿距离最小生成树与莫队算法
- LeetCode OJ 之 Product of Array Except Self (除了自身的数组的乘积)
- 基数排序
- hdu 1171 Big Event in HDU
- GetWindowText
- hdu 1171 Big Event in HDU
- Javascript函数的参数
- PGM格式文件
- unlock 306sh(Aquos Crystal 解锁)
- 用GDB调试程序(三)
- 【java工具类】DES加密