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. ubuntu 环境变量修改和恢复总结

    通常设置环境变量有三种方法: 一.临时设置export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64export PATH=$JAVA_HOME/:$ ...

  2. 微信公众号 SVG长按互动

    <section class="" style="display: block;width: 100%;height:667px;overflow:hidden;m ...

  3. webpack引入jQuery

    1. 本地文件引入 配置 const webpack=require('webpack'); module.exports={ resolve:{ alias:{ //绝对路径 jQuery:path ...

  4. CSS3如何实现圆圈转圈,附demo

    如图,如何实现圆圈转圈? 主要还是CSS3动画(只兼容了谷歌,需要兼容其它浏览器,加前缀即可) .move1 { animation: myMove1 5s ease-in infinite alte ...

  5. System.Web.Mvc.ViewEngineResult.cs

    ylbtech-System.Web.Mvc.ViewEngineResult.cs 1.程序集 System.Web.Mvc, Version=5.2.3.0, Culture=neutral, P ...

  6. Jeecg-Boot 2.0.1 版本发布,前后端分离快速开发平台

    Jeecg-Boot项目简介 Jeecg-boot 是一款基于代码生成器的快速开发平台! 采用前后端分离技术:SpringBoot,Mybatis,Shiro,JWT,Vue & Ant De ...

  7. 《DSP using MATLAB》Problem 8.3

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  8. C++【string】用法和例子

    /*** * string 基础api复习 * 8 AUG 2018 */ #include <iostream> #include <string> using namesp ...

  9. Windows API 第四篇 文件操作

    创建或打开文件(也可用于打开管道,油槽,硬件设备等): HANDLE CreateFile( LPCTSTR lpFileName, // file name DWORD dwDesiredAcces ...

  10. JZOJ5965【NOIP2018提高组D2T2】填数游戏

    题目 作为NOIP2018的题目,我觉得不需要把题目贴出来了. 大意就是,在一个n∗mn*mn∗m的010101矩阵中,从左上角到右下角的路径中,对于任意的两条,上面的那条小于下面的那条.问满足这样的 ...