Dividing

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 20635    Accepted Submission(s): 5813

Problem Description
Marsha
and Bill own a collection of marbles. They want to split the collection
among themselves so that both receive an equal share of the marbles.
This would be easy if all the marbles had the same value, because then
they could just split the collection in half. But unfortunately, some of
the marbles are larger, or more beautiful than others. So, Marsha and
Bill start by assigning a value, a natural number between one and six,
to each marble. Now they want to divide the marbles so that each of them
gets the same total value.
Unfortunately, they realize that it
might be impossible to divide the marbles in this way (even if the total
value of all marbles is even). For example, if there are one marble of
value 1, one of value 3 and two of value 4, then they cannot be split
into sets of equal value. So, they ask you to write a program that
checks whether there is a fair partition of the marbles.
 
Input
Each
line in the input describes one collection of marbles to be divided.
The lines consist of six non-negative integers n1, n2, ..., n6, where ni
is the number of marbles of value i. So, the example from above would
be described by the input-line ``1 0 1 2 0 0''. The maximum total number
of marbles will be 20000.

The last line of the input file will be ``0 0 0 0 0 0''; do not process this line.

 
Output
For
each colletcion, output ``Collection #k:'', where k is the number of
the test case, and then either ``Can be divided.'' or ``Can't be
divided.''.

Output a blank line after each test case.

 
Sample Input
1 0 1 2 0 0
1 0 0 0 1 1
0 0 0 0 0 0
 
Sample Output
Collection #1:
Can't be divided.
 
Collection #2:
Can be divided.
 
Source

哎~dp好难..........

题意:每行六个数,若都为零则结束,否则,第几个数代表价值为几的东西有几个,东西数量不超过20万,问所有东西能不能分成两堆价值相等的。

能的话输出 Can..,否则Can't...,每组输出后面有个空行~

多重背包加优化..暂时还是不能深入的理解dp的奥义..烦恼ing...

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <climits>
#include <queue>
#define ll long long using namespace std;
int dp[],w[];
int main(void)
{
int ans,sum,cnt = ;
while(scanf("%d",&w[]) != -)
{
sum = ;
ans = ;
if(w[] != ) ans= ;
sum += w[];
for(int i = ; i <= ; i++)
{
scanf("%d",&w[i]);
sum += w[i]*i;
if(w[i])
ans = ;
}
if(!ans)
break;
if(sum % == )
{
printf("Collection #%d:\nCan't be divided.\n\n",cnt++);
}
else
{
memset(dp,,sizeof(dp));
for(int i = ; i <= w[i] && i <= sum/; i++) dp[i] = ;
for(int i = ; i <= ; i++)
for(int j = sum/; j >= ; j--)
{
if(dp[j] == )
continue;
for(int k = ; k <= w[i] && k *i+j <= sum/; k++)
{
if(dp[k*i+j]) break;
dp[k*i+j] = ;
}
}
if(dp[sum/] == )
printf("Collection #%d:\nCan be divided.\n\n",cnt++);
else
printf("Collection #%d:\nCan't be divided.\n\n",cnt++);
} }
return ;
}

hdu 1059 Dividing(多重背包优化)的更多相关文章

  1. hdu 1059 Dividing 多重背包

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

  2. POJ 1014 / HDU 1059 Dividing 多重背包+二进制分解

    Problem Description Marsha and Bill own a collection of marbles. They want to split the collection a ...

  3. HDU 1059(多重背包加二进制优化)

    http://acm.hdu.edu.cn/showproblem.php?pid=1059 Dividing Time Limit: 2000/1000 MS (Java/Others)    Me ...

  4. HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化)

    HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那 ...

  5. hdu 1059 Dividing bitset 多重背包

    bitset做法 #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a ...

  6. HDU 1059 Dividing 分配(多重背包,母函数)

    题意: 两个人共同收藏了一些石头,现在要分道扬镳,得分资产了,石头具有不同的收藏价值,分别为1.2.3.4.5.6共6个价钱.问:是否能公平分配? 输入: 每行为一个测试例子,每行包括6个数字,分别对 ...

  7. 题解报告:hdu 1059 Dividing(多重背包、多重部分和问题)

    Problem Description Marsha and Bill own a collection of marbles. They want to split the collection a ...

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

  9. ACM学习历程—HDU 1059 Dividing(dp && 多重背包)

    Description Marsha and Bill own a collection of marbles. They want to split the collection among the ...

随机推荐

  1. sort的cmp函数

    sort的cmp函数只能写return a>b;或者return a<b;

  2. csscomb配置文件说明

    { "always-semicolon": true, // 总是显示分号 "block-indent": " ", // 代码块缩进,可以 ...

  3. leetcode-117-填充每个节点的下一个右侧节点指针②

    ---恢复内容开始--- 题目描述: 方法一:层次遍历 """ # Definition for a Node. class Node: def __init__(sel ...

  4. [JZOJ4640] 【GDOI2017模拟7.15】妖怪

    题目 描述 题目大意 给你一堆aia_iai​和bib_ibi​(方便起见用的变量和上面不一样),让你搞出一个xxx(相当于题目中的ba\frac{b}{a}ab​,随便推推就能知道), 使得max⁡ ...

  5. 莫烦PyTorch学习笔记(四)——回归

    下面的代码说明个整个神经网络模拟回归的过程,代码含有详细注释,直接贴下来了 import torch from torch.autograd import Variable import torch. ...

  6. springboot让内置tomcat失效

    一.POM(去除内嵌tomcat后,需要添加servlet依赖) <dependency> <groupId>org.springframework.boot</grou ...

  7. C++ 变量、常量、符号常量

    变量: int i = 0;  // i 是变量 i=5;         //i 可以修改 变量就是程序内一个内存位置的符号名,在该内存位置可以保存数据,并可以通过符号名对该内存地址存放的数据进行访 ...

  8. python格式化输出%,while else

    一.格式化输出% 需求:自我介绍模板 #格式化输出 # % s d %占位符,占个位置 s(字符串),d(数字)替换内容的类型 name = input('请输入姓名:') age = input(' ...

  9. 主从复制系列C

    近日接到一个故障,主从异步方式,主 crash后,从不可用,检查发现从机Read_Master_Log_Pos与Exec_Master_Log_Pos不一致,似乎还有binlog在回放中,HA在等回放 ...

  10. bzoj1706 relays 奶牛接力跑 线性代数

    题目描述 FJ的N(2 <= N <= 1,000,000)头奶牛选择了接力跑作为她们的日常锻炼项目.至于进行接力跑的地点 自然是在牧场中现有的T(2 <= T <= 100) ...