HDOJ 1709 The Balance(母函数)
The Balance
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4497 Accepted Submission(s): 1808
1 2 4
3
9 2 1
2
4 5
//对每个砝码可以不用,也可以放到左边或右边。。。。。 #include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int n,m;
int a[];
int c1[],c2[];
const int cc=; int main()
{
while(scanf("%d",&n)!=EOF)
{
int m=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
m+=a[i];
} memset(c1,,sizeof(c1));
memset(c2,,sizeof(c2)); for(int i=-a[];i<=a[];i+=a[])
{
c1[i+cc]=;
} for(int i=;i<=n;i++)
{
for(int j=-m;j<=m;j++)
{
for(int k=-a[i];k+j<=m&&k<=a[i];k+=a[i])
{
c2[k+j+cc]+=c1[j+cc];
}
}
for(int j=-m;j<=m;j++)
{
c1[j+cc]=c2[j+cc];
c2[j+cc]=;
}
} int aas[]={};
int ans=;
for(int i=;i<=m;i++)
{
if(c1[i+cc]||c1[-i+cc]) ;
else
{
aas[ans]=i;
ans++;
}
} printf("%d\n",ans);
for(int i=;i<ans;i++)
{
if(i==)
printf("%d",aas[i]);
else
printf(" %d",aas[i]);
}
if(ans)
putchar(); } return ;
}
HDOJ 1709 The Balance(母函数)的更多相关文章
- 组合数学 - 母函数的运用 --- hdu 1709 :The Balance
The Balance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 【HDOJ】1709 The Balance
母函数,指数可以为1也可以为-1,扩大指数加消减发现TLE,于是采用绝对值就过了. #include <stdio.h> #include <string.h> #define ...
- hdu 1709 The Balance(母函数)
题意: 有一个天平.有N个砝码.重量分别是A1...AN. 问重量[1..S]中有多少种重量是无法利用这个天平和这些砝码称出来的. S是N个砝码的重量总和. 思路: 对于每一个砝码来说,有三种:不放, ...
- The Balance(母函数)
The Balance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- hdu_1790_The Balance(母函数)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1709 题意:给你一些砝码,让你输出1—sum中不能称出的重量 题解:直接上母函数,在合并括号的时候有加 ...
- hdu 1709 The Balance
母函数的特殊情况,左右两边都可以放,如样例1,2,9 母函数为(1+x+1/x)*(1+x^2+1/x^2)*(1+x^9+1/x^9) 化简为(1+x+x^2)*(1+x^2+x^4)*(1+x^9 ...
- HDU 1709 The Balance( DP )
The Balance Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDOJ 2069 Coin Change(母函数)
Coin Change Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDOJ 2079 选课时间(母函数)
选课时间(题目已修改,注意读题) Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- LinqToSql和ASP.NET Entity FrameWork 中使用事务
ASP.NET Entity FrameWork中: int flag = -1; if (this.URPmanagementEntities1.Connection.State != System ...
- plantuml
brew install graphviz https://github.com/jvantuyl/sublime_diagram_plugin
- JavaWeb之Servlet:请求 与 响应
1 引入 浏览器和服务器的种类都有很多,要在它们之间通讯,必定要遵循一定的准则,而http协议就是这样的一个"准则". Http协议:规定了 浏览器 和 服务器 数据传输的一种格式 ...
- 成长记录 if语句输出 由大到小的数字
#include<stdio.h> void main() { float a,b,c,d,e,f,g,t; scanf("%f,%f,%f,%f,%f,%f,%f", ...
- Union-SQL Server学习笔记
1.简单笔记 数据库查询语句中,通过UNION组合查询语句,可以将两个或更多查询的结果组合为单个结果集,该结果集包含组合查询中的所有查询的全部行. 利用UNION语句可以实现将不同数据表中符合条件,不 ...
- Web开发者和设计师必须要知道的 iOS 8 十个变化
原文出处: mobilexweb 译文出处:罗磊(@罗罗磊磊) 欢迎分享原创到伯乐头条 喜大普奔,喜极而泣,喜当爹,随着iPhone 6和iPhone 6 plus的上市,ios 8终于在上周 ...
- iOS8 蓝牙设备的重连接(retrieve) Swift实现
今天App写到了蓝牙重连的阶段,以前针对sdk 6.0写的代码,蓝牙设备的回复是通过 - (void)retrievePeripherals:(NSArray *)peripheralUUIDs 然后 ...
- ExtJS 提示
要使ExtJS支持提示,需要在onReady的function中添加如下语句: Ext.QuickTips.init();//支持tips提示 Ext.form.Field.prototype.msg ...
- 快速生成R语言报告(markdown+Rstudio)
先预览一下用Markdown写的报告[http://rpubs.com/loness/167347],这是HTML格式,你也可以导出Word.pdf,但是导出pdf时文中不能有中文,但是可以使用“pd ...
- 莫名戳中"肋骨"的文章
1 起初,我们总是会害怕,害怕不能得到自己渴望的物质生活,害怕遇不到那个好好爱自己的人,害怕失去青春也换不回事业上的进步,害怕会做下一个让自己悔恨的决定,可这一路,我们就是这样踩着自己的害怕和悔恨走来 ...