Description

小Q手里有n(n<=1000) 个硬币,每枚硬币有一定的金额(200=>x>=1)他想知道,用这些硬币(每枚硬币只能用一次,但可能会有等面值的用两次) 能组成多少种不同的金额?

Input

第一行 n,表示第二行一共有n个数字,第二行 表示n个数字

Output

第一行 输出 m, 表示可以组成多少种不同的金额第二行 按照从小到大的顺序输出所有的金额。 注意,每行的结尾,不要有空格,否则你的答案可能会被判错。

Sample Input 1

2
1 2

Sample Output 1

3
1 2 3

Sample Input 2

2
1 1

Sample Output 2

2
1 2 01背包的未装满的情况
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<cmath>
#define Inf 0x3f3f3f3f
const int maxn=1e5+;
typedef long long ll;
using namespace std;
int a[maxn],dp[];
int main()
{
int n;
cin>>n;
int sum=;
for(int t=;t<=n;t++)
{
scanf("%d",&a[t]);
sum+=a[t];
}
for(int t=;t<=sum;t++)
{
dp[t]=-Inf;
}
dp[]=;
for(int t=;t<=n;t++)
{
for(int j=sum;j>=a[t];j--)
{
dp[j]=max(dp[j],dp[j-a[t]]+a[t]);
}
}
int s[];
int cnt=;
for(int t=;t<=sum;t++)
{
if(dp[t]>=)
{ s[cnt++]=dp[t];
}
}
cout<<cnt<<endl;
for(int t=;t<cnt;t++)
{
if(t==)
{
printf("%d",s[t]);
}
else
{
printf(" %d",s[t]);
}
}
return ;
}

最新文章

  1. ecshop随机分类
  2. ReSharper 配置及用法
  3. Linq 查询结果 可能遵循 2 &#186;,2&#185;,2 &#178;,......增长计算
  4. 总结CSS3新特性(Transform篇)
  5. CSS控制XML与通过js解析xml然后通过html显示xml中的数据
  6. Two-Phase Commit (两阶段提交)
  7. matlab参数查询
  8. flash视频器播放器代码
  9. C# 将\u1234类型的字符转化成汉字
  10. DDD实践案例:引入事件驱动与中间件机制来实现后台管理功能
  11. Java Primitives and Bits
  12. freemarker.core.ParseException:Unexpected end of file reached
  13. centos7 编译安装greenplum5.7
  14. iOS 8 中如何集成 Touch ID 功能
  15. Ajax技术使用补充
  16. CAP:Alantany 谈 CAP
  17. php 页面调转导致session丢失解决方法
  18. nodejs多语句查询
  19. Python conda 入门
  20. 小程序登录、微信网页授权(Java版)

热门文章

  1. 分类模型的F1-score、Precision和Recall 计算过程
  2. Android 布局的一些控件的补充和布局的补充(今儿没课)
  3. python4.2参数传入
  4. Java 命令行 编译、执行、打包
  5. Python中 *args 和 **kwargs 的含义?
  6. MySQL数据库——数据约束
  7. Windows下,配置VS Code的Java开发环境
  8. 一个基于 Beego 的,能快速创建个人博客,cms 的系统
  9. Spring Cloud Config Client 超时与重试
  10. 三张图理解JavaScript原型链