A - Dividing

Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u

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 file describes one collection of marbles to be divided. The lines contain six non-negative integers n1 , . . . , 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 collection, 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. 解题:多重背包的二进制优化,第一次搞二进制优化啊。。。。。。无尽的WA
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
int dp[],w[] = {,,,,,,};
int num[],sum,val;
int main() {
int i,j,k,ks = ,temp,u;
int a[];
while(true) {
for(val = sum = ,i = ; i <= ; i++) {
scanf("%d",num+i);
sum += num[i];
val += i*num[i];
}
if(!sum) break;
printf("Collection #%d:\n",ks++);
if(val&) puts("Can't be divided.");
else {
temp = val>>;
memset(dp,,sizeof(dp));
for(i = ; i <= ; i++) {
int u = log2(num[i]);
for(k = ; k <= u; k++){
if(k == u){a[k] = num[i]-(<<u)+;}
else a[k] = <<k;
}
for(k = ; k <= u; k++){
for(j = temp; j >= a[k]*i; j--){
dp[j] = max(dp[j],dp[j-a[k]*i]+a[k]*i);
}
}
}
if(dp[temp] == temp) puts("Can be divided.");
else puts("Can't be divided.");
}
printf("\n");
}
return ;
}

xtu read problem training A - Dividing的更多相关文章

  1. xtu read problem training 3 B - Gears

    Gears Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 3789 ...

  2. xtu read problem training 3 A - The Child and Homework

    The Child and Homework Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on Code ...

  3. xtu read problem training 2 B - In 7-bit

    In 7-bit Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 3 ...

  4. xtu read problem training 4 A - Moving Tables

    Moving Tables Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ...

  5. xtu read problem training 4 B - Multiplication Puzzle

    Multiplication Puzzle Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. O ...

  6. xtu read problem training B - Tour

    B - Tour Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Descriptio ...

  7. [LeetCode&Python] Problem 728. Self Dividing Numbers

    A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is ...

  8. 【Leetcode_easy】728. Self Dividing Numbers

    problem 728. Self Dividing Numbers solution1: 使用string类型来表示每位上的数字: class Solution { public: vector&l ...

  9. Codeforces 380 简要题解

    ABC见上一篇. 感觉这场比赛很有数学气息. D: 显然必须要贴着之前的人坐下. 首先考虑没有限制的方案数.就是2n - 1(我们把1固定,其他的都只有两种方案,放完后长度为n) 我们发现对于一个限制 ...

随机推荐

  1. 贪心 Codeforces Round #303 (Div. 2) B. Equidistant String

    题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #includ ...

  2. 1-2JDK的安装和环境变量设置

    JDK的下载和安装 可以去oracle官网里面下载JDK:http://www.oracle.com 英文不好的同学可以通过下面这个百度网盘的链接进行下载:http://pan.baidu.com/s ...

  3. Java中“==”的使用,以及“==”和equal的比较

    int i02=59 ,这是一个基本类型,存储在栈中. Integer i03 =Integer.valueOf(59); 因为 IntegerCache 中已经存在此对象,所以,直接返回引用. In ...

  4. Java 学习列表

    这是从450家企业的招聘信息中统计而来,相对来说还是比较真实的,虽然有些公司的招聘要求万年不变,但还是可以大致反应企业的招聘要求的.

  5. 基于Java实现的冒泡排序算法

    冒泡排序是一种简单基础的排序算法,相信在大学课堂里老师已经讲过了,现在我基于Java来实现一遍. 简述 冒泡排序正如其关键词一样,杂乱的气泡经过浮动,最后大的气泡飘到了上面而小的气泡在下面,无序的元素 ...

  6. void运算符

    void是一元运算符,它出现在操作数之前,操作数可以是任意类型,操作数会照常计算,但忽略计算结果并返回undefined.由于void会忽略操作数的值,因此在操作数具有副作用的时候使用void来让程序 ...

  7. Selenium私房菜系列3 -- Selenium API参考手册【ZZ】

    大家在编写测试案例想查阅Selenium API说明时,可以查阅本文,否则请跳过! (注:这里API版本比较老,新版本的Selenium的API在这里不一定能找到.) Selenium API说明文档 ...

  8. Elasticsearch 插入地理索引文档一直为空

    今天在获取插入索引数据的时候,一直提示插入不成功,尝试了很多方法,原来是因为在插入的时候应该先 插入Latitude后插入longitude修改后的代码如下 public boolean insert ...

  9. 在云环境上使用SLF4J对Java程序进行日志记录

    我开发了一个Java应用,部署到云环境上之后,用postman测试发现不能按照我期望的工作,但是返回的消息对我没有任何帮助. 因为部署在云端的应用很难像本地Java应用一样调试,所以我打算用SLF4J ...

  10. 前端基础入门第一阶段-Web前端开发基础环境配置

    Web前端和全栈的定义: A.什么是传统传统web前端:需要把设计师的设计稿,切完图,写标签和样式,实现JS的效果,简而言之即只需要掌握HTML的页面结构,CSS的页面样式,javaScript页面的 ...