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. UESTC_方老师分身 I CDOJ 914

    方老师分身 I Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submit S ...

  2. java 8 中lambda表达式学习

    转自 http://blog.csdn.net/renfufei/article/details/24600507 http://www.jdon.com/idea/java/10-example-o ...

  3. FWA winner | Car Visualizer WebGL

    FWA winner | Car Visualizer WebGL Car Visualizer made in WebGL using ThreeJS. It requires a modern b ...

  4. UGUI Text控件

    学习UGUI的Text控件,用于显示文本!.  基本属性就不再啰嗦了! Alignment: 文字以 水平和垂直 对齐方式, Horizontal Overflow: 水平 Wrap: 文字大小和数量 ...

  5. Hibernate中save、saveorupdate、persist方法的区别

    在Hibernate中,save().saveOrUpdate()和persist()都是用于将对象保存到数据库中的方法,但其中有些细微的差别.例如,save()只能INSERT记录,但是saveOr ...

  6. Old Sorting(转化成单调序列的最小次数,置换群思想)

     Old Sorting Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit S ...

  7. react redux 相关技术

    React全都是围绕着组件的, 所以React基础也就是:写组件的jsx.组件的生命周期以及组件的属性和状态.jsx,只要是用过html模板的分分钟就能写了: 所谓生命周期就是组件在创建.销毁.更新阶 ...

  8. C# DES 加密解密

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.S ...

  9. html中的表格 bootstrap-table

    1 bootstrap-table 官网: http://bootstrap-table.wenzhixin.net.cn/ 2

  10. PHP基础温习之echo print printf sprintf print_r var_dump的用法与区别

    一.echoecho() 实际上不是一个函数,是php语句,因此您无需对其使用括号.不过,如果您希望向 echo() 传递一个以上的参数,那么使用括号会发生解析错误.而且echo是返回void的,并不 ...