*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 ...
随机推荐
- WEB端实现打印
首先需要下载一个JQ插件: 地址: http://files.cnblogs.com/files/SabWoF/jq%E6%89%93%E5%8D%B0%E6%8F%92%E4%BB%B6%E5%AE ...
- Invoke的使用情景
直接看代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Dat ...
- C# RSA加密解密
1.解析密钥 /// <summary> /// 把二进制密钥解析成RSACryptoServiceProvider /// </summary> /// <param ...
- tmpfs详解
一,tmpfs介绍 1. tmpfs是一种虚拟内存文件系统,正如这个定义它最大的特点就是它的存储空间在VM里面(什么是VM?后面介绍) 2. VM是由linux内核里面的vm子系统管理的东西,现在大多 ...
- 使用Lucene索引和检索POI数据
1.简介 关于空间数据搜索,以前写过<使用Solr进行空间搜索>这篇文章,是基于Solr的GIS数据的索引和检索. Solr和ElasticSearch这两者都是基于Lucene实现的,两 ...
- 使用Word 2013发布cnblogs随笔
博客园支持Word或者OneNote一键发布文章. 获取cnblogs的URL地址,类似http://rpc.cnblogs.com/metaweblog/your_name 打开word中的管理账户 ...
- CSS3 Loading(加载)动画效果
1.html 部分 <div class="spinner"> <div class="rect1"></div> < ...
- CozyRSS开发记录8-解析一份RSS
CozyRSS开发记录8-解析一份RSS 1.使用Rss20FeedFormatter解析RSS 使用Rss20FeedFormatter配合XmlReader来解析RSS非常的简单,几行搞定: 来试 ...
- Tomcat 9.0安装配置(转)
http://www.cnblogs.com/saratearing/p/5811866.html
- conda安装包
前面讲了有关conda改变镜像提高安装速度,这里来解决很多实用C写的酷,在Windows下不好安装的解决方案 1. 寻找wheel预编译文件 没有的话 2.使用conda命令安装 没有该包的话 3.实 ...