有价值为1~6的宝物各num[i]个,求能否分成价值相等的两部分。

#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#define inf 0x3f3f3f3f
#define ll long long
#define mod 1000000007
using namespace std; int dp[120010],num[10],v; void pack01(int c,int w)
{
for(int i=v;i>=c;i--)
dp[i]=max(dp[i],dp[i-c]+w);
} void packall(int c,int w)
{
for(int i=c;i<=v;i++)
dp[i]=max(dp[i],dp[i-c]+w);
} void mulpack(int c,int w,int n)
{
if(c*n>=v)
packall(c,w);
else
{
int i=1;
while(i<n)
{
pack01(c*i,w*i);
n-=i;
i+=i;
}
pack01(c*n,w*n);
}
} int main()
{
int cas=1,i,j,sum;//在这里多定义了一个v 导致一直出不来例子
while(1)
{
sum=0;
for(i=1;i<=6;i++)
{
scanf("%d",&num[i]);
sum+=(num[i]*i);//WA
}
if(sum==0) break;
printf("Collection #%d:\n",cas++);
if(sum&1)
{
printf("Can't be divided.\n\n");
continue;
} memset(dp,0,sizeof dp);
v=sum/2;
for(i=1;i<=6;i++)
if(num[i]) mulpack(i,i,num[i]);
if(dp[v]==v) printf("Can be divided.\n\n");
else printf("Can't be divided.\n\n");
}
return 0;
}

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

  1. hdu1059 Dividing ——多重背包

    link:http://acm.hdu.edu.cn/showproblem.php?pid=1059 最简单的那种 #include <iostream> #include <cs ...

  2. poj1014二进制优化多重背包

    Dividing Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53029   Accepted: 13506 Descri ...

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

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

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

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

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

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

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

  7. hdu 1059 Dividing 多重背包

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

  8. Dividing 多重背包 倍增DP

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

  9. POJ 1014 Dividing 多重背包

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

随机推荐

  1. [SDOI2008]沙拉公主的困惑 线性筛_欧拉函数_逆元_快速幂

    Code: #include<cstdio> using namespace std; typedef long long ll; const int maxn=10000000+1; l ...

  2. HDU-5685 Problem A 求乘法逆元

    题目链接:https://cn.vjudge.net/problem/HDU-5685 题意 给一个字符串S和一个哈希算法 $ H(s)=\prod_{i=1}^{i\leq len(s)}(S_{i ...

  3. CAS-ERR Cannot create a session after the response has been committed

    现象: 当cas 登录人数较少时候没有错误,但是用户过多时候出现下列err May-2016 18:09:11.932 SEVERE [http-nio-8080-exec-52] org.apach ...

  4. SQL Server 2008 备份数据库

    1.打开SQL , 找到要备份的数据库 , 右键 >> 任务 >>备份 2.弹出 [ 备份数据库对话框 ] ,如图: 3.点击加入 [ button ] . 例如以下图: 4. ...

  5. codeforces #313(div 2)

    B. Gerald is into Art time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  6. nj03---阻塞和线程

    Node.js最大的特性就是"异步式I/O"与事件紧密结合的编程模式.这种模式与传统的同步式IO线性的编程思路有很大的不同,因为控制流很大程度上要靠"事件"和& ...

  7. 有关 IE11

    IE10/IE11 中 99% 的 CSS3 属性不需要写 -ms- 前缀: IE9/IE10/IE11 默认开启 GPU 加速,效果比同期 Chrome 版本(如 35)流畅: IE11 的字体渲染 ...

  8. Android——PullToRefresh自动刷新

    需求:强制刷新 方法一: PullToRefreshListView本身提供了一个setRefreshing()接口,调用该接口会自动触发下拉刷新的操作(前提是支持下拉刷新).按照一般的操作我们直接在 ...

  9. PostgreSQL环境中查看SQL执行计划示例

    explain   analyze ,format,buffers, format :TEXT, XML, JSON, or YAML. EXPLAIN (ANALYZE,buffers,format ...

  10. 976 C. Nested Segments

    You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task ...