首页
诗词
字典
板报
句子
名言
友答
励志
学校
网站地图
编程
C++
C语言
C++ Builder
VB
PB
Ruby Rails
perl python
编程
其他开发语言
VBA
VC/MFC
当前位置:
首页
>
教程频道
>
开发语言
>
编程
>
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;}
查看更多
下一篇
本文网址:
https://www.reader8.net/jiaocheng/20120801/1962848.html
读书人精选
热点排行
maven 项目平添Maven Dependencies Libr
java类静态域、块,非静态域、块,结构函
Golang的slice圈套
Spring2 兑现AOP编程的两种实现方法
树的底层实现(下)
多线程程序的评量基准
struts2札记之第七讲
jquery 用ID取某个元素上的某个ID元素
聚合总结
步骤的重写和重载