The Balance

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7212    Accepted Submission(s): 2978

Problem Description
Now you are asked to measure a dose of medicine with a balance and a number of weights. Certainly it is not always achievable. So you should find out the qualities which cannot be measured from the range [1,S]. S is the total quality of all the weights.
 
Input
The input consists of multiple test cases, and each case begins with a single positive integer N (1<=N<=100) on a line by itself indicating the number of weights you have. Followed by N integers Ai (1<=i<=N), indicating the quality of each weight where 1<=Ai<=100.
 
Output
For each input set, you should first print a line specifying the number of qualities which cannot be measured. Then print another line which consists all the irrealizable qualities if the number is not zero.
 
Sample Input
3
1 2 4
3
9 2 1
 
Sample Output
0
2
4 5
 

题解:天平称药粉,为了这个题,我把母函数重刷了一遍,一遍A了;其实就是给一些钱,让计算在1~sum之间,有哪些钱不能被表示;sum等于给的Ai和;

我的思路是把所有的Ai再求一遍相反数,每个Ai有1个;

(1 + x^A[0])*(1 + x^A[1])*......*(1 + x^A[2 * n - 1]);

代码:

extern "C++"{
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
const int INF = 0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
typedef long long LL;
typedef unsigned long long ULL; void SI(int &x){scanf("%d",&x);}
void SI(double &x){scanf("%lf",&x);}
void SI(LL &x){scanf("%lld",&x);}
void SI(char *x){scanf("%s",x);} }
const int MAXN = ;
int a[MAXN],b[MAXN];
int p[MAXN],m[MAXN];
int v[MAXN];
int ans[MAXN];
int main(){
int N;
while(~scanf("%d",&N)){
int sum = ;
for(int i = ;i < N; i++)scanf("%d",&v[i]),sum += v[i];
for(int i = N ;i < *N ;i++){
v[i] = -v[i - N];
}
N *= ;
mem(a,);mem(b,);
a[] = ;a[v[] ] = ;
for(int i = ;i < N;i++){
for(int j = ;j <= sum;j++){
for(int k = ;k <= ;k++){
if(j + k * v[i] < )
continue;
b[j + k * v[i] ] += a[j];
}
}
for(int j = ;j <= sum;j++){
a[j] = b[j];b[j] = ;
}
}
int tp = ;
for(int i = ;i <= sum;i++){
if(!a[i])ans[tp++] = i;
}
printf("%d\n",tp);
if(!tp)continue;
for(int i = ;i < tp;i++){
if(i)printf(" ");
printf("%d",ans[i]);
}
puts("");
}
return ;
}

The Balance(母函数)的更多相关文章

  1. HDOJ 1709 The Balance(母函数)

    The Balance Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  2. hdu_1790_The Balance(母函数)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1709 题意:给你一些砝码,让你输出1—sum中不能称出的重量 题解:直接上母函数,在合并括号的时候有加 ...

  3. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  4. 组合数学 - 母函数的运用 --- hdu 1709 :The Balance

    The Balance Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. hdu_5616_Jam's balance(暴力枚举子集||母函数)

    题目连接:hdu_5616_Jam's balance 题意: 给你一些砝码,和一些要被称出的重量,如果这些砝码能称出来输出YES,否则输出NO 题解:我们想想,这题求组合方式,我们这里可以直接用母函 ...

  6. HDU 1709 母函数天平问题 可出现减法的情况 The Balance

    The Balance Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. The Balance HDU - 1709 母函数(板子变化)

    题意: 现在你被要求用天平和一些砝码来量一剂药.当然,这并不总是可以做到的.所以你应该找出那些不能从范围[1,S]中测量出来的品质.S是所有重量的总质量. 输入一个n,后面有n个数,表示这n个物品的质 ...

  8. hdu 1709 The Balance(母函数)

    题意: 有一个天平.有N个砝码.重量分别是A1...AN. 问重量[1..S]中有多少种重量是无法利用这个天平和这些砝码称出来的. S是N个砝码的重量总和. 思路: 对于每一个砝码来说,有三种:不放, ...

  9. 母函数 <普通母函数(HDU - 1028 ) && 指数型母函数(hdu1521)>

    给出我初学时看的文章:母函数(对于初学者的最容易理解的) 普通母函数--------->HDU - 1028 例题:若有1克.2克.3克.4克的砝码各一 枚,能称出哪几种重量?各有几种可能方案? ...

随机推荐

  1. Implement Hash Map Using Primitive Types

    A small coding test that I encountered today. Question Using only primitive types, implement a fixed ...

  2. linux 有名管道(FIFO)

    http://blog.csdn.net/firefoxbug/article/details/8137762 linux 有名管道(FIFO) 管道的缓冲区是有限的(管道制存在于内存中,在管道创建时 ...

  3. 【错误】:Could not open JDBC Connection for transaction; nested exception is: Communications link failure;The last packet sent successfully to the server was 1 milliseconds ago

    # #错误日志 2016-11-10 16:19:20,834 ERROR [org.quartz.core.JobRunShell] - Job DEFAULT.jobtask threw an u ...

  4. Python的if判断与while循环

    1.if判断 Python 编程中 if 语句用于控制程序的执行,基本形式为: if 判断条件: 执行语句 else: 执行语句 Python中使用缩进代替c语言中的大括号,来告诉程序所执行的内容. ...

  5. QUARTZ CRON

    本文来自:http://www.blogjava.net/crazycy/archive/2013/06/06/400287.html 每次使用Quartz Cron的时候都要去查manual doc ...

  6. 怎样使用jetty

    一直都听说jetty跟Tomcat一样,是一个web容器.之前做项目的时候,也使用过jetty,只是当时jetty是作为一个插件,跟maven集成使用的.那个时候,因为是第一次使用jetty,感觉je ...

  7. App Store不能下载一直等待中的两种解决办法

    1,重启手机,之后确认是否得到改善 2,重启不行,更改WiFi的dns为114.114.114.114或者223.5.5.5 或 223.6.6.6,再重启手机 ps:我是第二种方法

  8. 关于mysql binlog日志的格式说明

    Binary Log 记录方式 Row Level Binary Log会记录成每一行数据被修改的形式,然后在Slave端再对相同的数据进行修改. 如果修改了表的结构,那么binlog日志记录的是重新 ...

  9. android stagefright基本流程总结

    数据流的封装一. 由数据源DataSource生成MediaExtractor. 通过MediaExtractor::Create(dataSource)来实现.Create方法通过两步来生成相应的M ...

  10. 单链表(Single Linked List)

    链表的结点结构  ┌───┬───┐  │data|next│  └───┴───┘ data域--存放结点值的数据域 next域--存放结点的直接后继的地址(位置)的指针域(链域) 实例:从终端输入 ...