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. Word Ladder 解答

    Question Given two words (beginWord and endWord), and a dictionary's word list, find the length of s ...

  2. InternetExplorer 表单及用户名密码提交

    陆ftp或者其他类似需要输入密码的站点,可以在url中直接输入用户名密码,格式为: ftp://username:password@url 另外一种情况是,如果是表单提交的也可以通过url填写,如: ...

  3. Unity 生命周期

    原文翻译:            Execution Order of Event Functions            事件函数的执行顺序                        Edit ...

  4. 并行任务task

    http://msdn.microsoft.com/zh-cn/library/dd537609(v=vs.110).aspx http://www.cnblogs.com/yangecnu/p/So ...

  5. windows下sqlplus / as sysdba报ora-12560的解决方法

    环境:win7_64位.数据库版本ORACLE11G_R2 在CMD窗口,使用下面三个命令可正常连接数据库:C:\Users\Administrator> sqplus /nolog C:\Us ...

  6. 【巧妙算法系列】【Uva 11464】 - Even Parity 偶数矩阵

    偶数矩阵(Even Parity, UVa 11464) 给你一个n×n的01矩阵(每个元素非0即1),你的任务是把尽量少的0变成1,使得每个元素的上.下.左.右的元素(如果存在的话)之和均为偶数.比 ...

  7. js库开发--参数传递及方法修改

    <!DOCTYPE html><html>    <head>        <meta charset="UTF-8">      ...

  8. C#实现WinForm传值实例解析

    C#实现WinForm传值的问题经常会做为公司面试的题目,那么作为学习C#以及WinForm传值,我们需要掌握哪些方法和思路呢?下面我们就向你介绍详细的思路和实现的具体步骤,希望对你有所帮助. C#实 ...

  9. PHP学习笔记三

    <?php $a=56; $b=++$a; //等价于 $a=$a+1; $b=$a; /////2. $e=false||true;//结果为true $f=false or true;//输 ...

  10. iOS二进制和资源包的自检

    因为现在做的是企业版的APP,不能保证用户不越狱,也不能保证有些用户喜欢自己修改ipa包里的资源文件,比如更换一些资源图片.因此,我们有必要在请求报文中,增加正版应用的二进制和资源文件的标识,让服务器 ...