*HDU 1709 母函数
The Balance
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 7677 Accepted Submission(s): 3187
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 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.
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.
//a克砝码有三种状态,放在天平的左端可以认为是x^-a,不放是1,放在右边是x^a,这样(x^-a,1,x^a)。但是负的重量没法用数组存,所以
//可以用abs(k-j)表示左右砝码的差得到c2[abs(k-j)]+=c1[j];
#include<bits\stdc++.h>
using namespace std;
int n,sum,a[],c1[],c2[];
void solve()
{
memset(c1,,sizeof(c1));
memset(c2,,sizeof(c2));
c1[]=;c1[a[]]=; //第一个表达式的系数
for(int i=;i<=n;i++)
{
for(int j=;j<=sum;j++)
{
int k=;
if(k+j<=sum)
c2[k+j]+=c1[j];
k=a[i];
if(k+j<=sum)
c2[k+j]+=c1[j];
int tem=fabs(k-j);
if(tem<=sum)
c2[tem]+=c1[j];
}
for(int j=;j<=sum;j++)
{
c1[j]=c2[j];
c2[j]=;
}
}
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
sum=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
}
solve();
int t=,ans[];
for(int i=;i<=sum;i++)
if(c1[i]==)
{
t++;
ans[t]=i;
}
printf("%d\n",t);
if(t){
for(int i=;i<t;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[t]);
}
}
return ;
}
*HDU 1709 母函数的更多相关文章
- The Balance HDU - 1709 母函数(板子变化)
题意: 现在你被要求用天平和一些砝码来量一剂药.当然,这并不总是可以做到的.所以你应该找出那些不能从范围[1,S]中测量出来的品质.S是所有重量的总质量. 输入一个n,后面有n个数,表示这n个物品的质 ...
- HDU 1709 母函数天平问题 可出现减法的情况 The Balance
The Balance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 1028 母函数 一个数有几种相加方式
///hdu 1028 母函数 一个数有几种相加方式 #include<stdio.h> #include<string.h> #include<iostream> ...
- 组合数学 - 母函数的运用 --- hdu 1709 :The Balance
The Balance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 1709 The Balance(母函数)
题意: 有一个天平.有N个砝码.重量分别是A1...AN. 问重量[1..S]中有多少种重量是无法利用这个天平和这些砝码称出来的. S是N个砝码的重量总和. 思路: 对于每一个砝码来说,有三种:不放, ...
- HDU 2082 母函数模板题
找单词 Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Submit Status De ...
- Crisis of HDU(母函数)
Crisis of HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 1171 Big Event in HDU(母函数)
链接:hdu 1171 题意:这题能够理解为n种物品,每种物品的价值和数量已知,现要将总物品分为A,B两部分, 使得A,B的价值尽可能相等,且A>=B,求A,B的价值分别为多少 分析:这题能够用 ...
- 杭电1171 Big Event in HDU(母函数+多重背包解法)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
随机推荐
- [不断更新]iOS开发常用技术
1.修改默认初始化方法 构建便利构造器 修改默认init初始化 .m文件中 @implementation 类名 -(id)init{ self=[super init]; printf(" ...
- iOS 私有变量 私有方法
实例变量既可以在@interface中定义 也可以在@implementation中定义 在@implementation中的成员变量默认是私有的成员变量 并且和利用@private修饰的不太一样 在 ...
- linux无法挂载u盘
一般插入u盘都会自动挂载,但有时挂载不了,错误提示:can't find /dev/sdb in /etc/fstab:这时可能是U盘坏了,我们当然不希望是这样.也有可能是U盘使用的接口不对应导致系统 ...
- cacti 安装
cacti:是常用的一个监控软件(开源,免费) 特点:重图形,有数据历史,需要用到数据库的支持,支持web配置,默认不支持告警,可以加插件 cacti安装 1.安装扩展源epel (nagios 和z ...
- caffe机器学习自带图片分类器classify.py实现输出预测结果的概率及caffe的web_demo例子运行实例
caffe机器学习环境搭建及python接口编译参见我的上一篇博客:机器学习caffe环境搭建--redhat7.1和caffe的python接口编译 1.运行caffe图片分类器python接口 还 ...
- <c:if test="value ne, eq, lt, gt,...."> 用法
类别 运算符 算术运算符 + . - . * . / (或 div )和 % (或 mod ) 关系运算符 == (或 eq ). != (或 ne ). < (或 lt ). > (或 ...
- java回调机制
http://www.cnblogs.com/heshuchao/p/5376298.html
- java程序性能优化
一.避免在循环条件中使用复杂表达式 在不做编译优化的情况下,在循环中,循环条件会被反复计算,如果不使用复杂表达式,而使循环条件值不变的话,程序将会运行的更快. 例子: import java.util ...
- vnc远程运行3D游戏
使用的版本:VNC-5.2.3-Windows.exe vnc官网 安装的过程中需要输入license key,以下给出一些enterprise license(最大权限的License): K5 ...
- 继承映射关系 TPH、TPT、TPC<EntityFramework6.0>
每个类型一张表[TPT] 声明方式 public class Business { [Key] public int BusinessId { get; protected set; } public ...