诗词
字典
板报
句子
名言
励志
学校
友答
搜索
首页
中考频道
作文频道
公务员频道
出国留学
医药考试
司法考试
图书频道
外语考试
建筑工程
成人高考
故事频道
教程频道
文档频道
早教
星座频道
校园
求职招聘
考研频道
职业资格
自考频道
计算机考试
财会考试
高考频道
当前位置:
首页
>
教程频道
>
开发语言
>
编程
>
HDU1709 The Balance,雌函数套题
2012-08-01
HDU1709 The Balance,母函数套题因为放在天平上,所以可以放左右两边。。。所以记得不仅可以加,还可以减。。。/**
HDU1709 The Balance,母函数套题
因为放在天平上,所以可以放左右两边。。。所以记得不仅可以加,还可以减。。。
/******************************************************************************* # Author : Neo Fung # Email : neosfung@gmail.com # Last modified: 2012-06-13 16:07 # Filename: acm.cpp # Description : ******************************************************************************/#ifdef _MSC_VER#define DEBUG#define _CRT_SECURE_NO_DEPRECATE#endif#include <fstream>#include <stdio.h>#include <iostream>#include <string.h>#include <string>#include <limits.h>#include <algorithm>#include <math.h>#include <numeric>#include <functional>#include <ctype.h>#include <map>using namespace std;const int kMAX=100100;const double kEPS=10E-6;int ans[kMAX],tans[kMAX];int main(void){#ifdef DEBUG freopen("../stdin.txt","r",stdin); freopen("../stdout.txt","w",stdout); #endif int n,tmp; while(~scanf("%d",&n) && n) {map<int,int> mmap;int sum=0;while(n--){scanf("%d",&tmp);mmap[tmp]++;sum+=tmp;}memset(ans,0,sizeof(ans));memset(tans,0,sizeof(tans));ans[0]=1;for(map<int,int>::iterator iter=mmap.begin();iter!=mmap.end();++iter){for(int j=0;j<=sum;++j)if(ans[j]) {for(int k=0,remain=iter->second+1;k+j<=sum && remain;k+=iter->first,--remain) {tans[k+j]+=ans[j]; tans[abs(j-k)]+=ans[j]; } }memcpy(ans,tans,sizeof(ans));memset(tans,0,sizeof(tans));}int cnt=0;for(int i=1;i<=sum;++i)if(!ans[i])tans[cnt++]=i;printf("%d\n",cnt);for(int i=0;i<cnt;++i)printf("%d%c",tans[i],i==(cnt-1)?'\n':' '); } return 0;}