C. The Values You Can Make

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

Pari wants to buy an expensive chocolate from Arya. She has n coins, the value of the i-th coin is ci. The price of the chocolate is k, so Pari will take a subset of her coins with sum equal to k and give it to Arya.

Looking at her coins, a question came to her mind: after giving the coins to Arya, what values does Arya can make with them? She is jealous and she doesn't want Arya to make a lot of values. So she wants to know all the values x, such that Arya will be able to make xusing some subset of coins with the sum k.

Formally, Pari wants to know the values x such that there exists a subset of coins with the sum k such that some subset of this subset has the sum x, i.e. there is exists some way to pay for the chocolate, such that Arya will be able to make the sum x using these coins.

Input

The first line contains two integers n and k (1  ≤  n, k  ≤  500) — the number of coins and the price of the chocolate, respectively.

Next line will contain n integers c1, c2, ..., cn (1 ≤ ci ≤ 500) — the values of Pari's coins.

It's guaranteed that one can make value k using these coins.

Output

First line of the output must contain a single integer q— the number of suitable values x. Then print q integers in ascending order — the values that Arya can make for some subset of coins of Pari that pays for the chocolate.

Examples

input

6 18
5 6 1 10 12 2

output

16
0 1 2 3 5 6 7 8 10 11 12 13 15 16 17 18

input

3 50
25 25 50

output

3
0 25 50
 //2017-08-16
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ;
//dp[i][j]表示选取某些数使其和为i的时候,能否组成j。转移方程:dp[i][j] = dp[i][j+arr[p]] = 1 | dp[i-arr[p]][j] == 1
int arr[N], dp[N][N], ans[N], tot;
int n, k;
bool vis[N], book[N]; int main()
{
while(cin>>n>>k){
for(int i = ; i < n; i++){
cin>>arr[i];
}
memset(dp, , sizeof(dp));
dp[][] = ;
for(int p = ; p < n; p++){
for(int i = k; i >= arr[p]; i--){
for(int j = ; j+arr[p] <= k; j++)
if(dp[i-arr[p]][j]){
dp[i][j] = dp[i][j+arr[p]] = ;
}
}
}
tot = ;
for(int j = ; j <= k; j++){
if(dp[k][j])ans[tot++] = j;
}
cout<<tot<<endl;
for(int i = ; i < tot; i++)
if(i == tot-)cout<<ans[i]<<endl;
else cout<<ans[i]<<" ";
} return ;
}

最新文章

  1. 《Entity Framework 6 Recipes》翻译系列 (3) -----第二章 实体数据建模基础之创建一个简单的模型
  2. C++:C++的两种多态形式
  3. storm 配置,呵呵。
  4. Oracle 数值函数
  5. 微信小程序实例-获取当前的地理位置、速度
  6. 使用awk统计字段重复实践
  7. Gartner2014年魔力象限(商业智能和分析平台)
  8. PullToRefresh下拉刷新 加载更多 详解 +示例
  9. 分子量(Molar Mass,ACM/ICPC Seoul 2007,UVa 1586)
  10. HDU5477(模拟)
  11. asp.net微软图表控件使用示例
  12. 安装mysql时出现应用程序无法正常启动(0xc000007b)
  13. 迅为4412开发板QtE系统源码-屏幕横竖屏切换修改方法
  14. Light OJ 1058
  15. geotrellis使用(四十二)将 Shp 文件转为 GeoJson
  16. [转]Hadoop参数汇总
  17. Tomcat配置远程调试端口(windows、Linux)
  18. spring boot 1.5.3项目放到resin4.0.53报错
  19. MySQL C API的一个让我头疼的问题,获得一行记录中包括NULL
  20. H5,PC网页屏幕尺寸相关整理(scrollLeft,scrollWidth,clientWidth,offsetWidth)

热门文章

  1. Linux - route &amp; traceroute &amp; ip
  2. 好用的在线工具汇总:Iconfont图标,数据mock,时间函数库,颜色查询 等
  3. 没啥事用C语言写一个Trie tree玩玩,支持中英文,用g++编译通过
  4. Windows 8.1 GetVersionEx返回6.2.9200 的问题!
  5. IDEA中Git的使用基础
  6. Linux MBR扇区误删恢复
  7. Java运行时,指定程序文件的编码
  8. java学习碰到死胡同了
  9. MySql主从同步和延迟同步
  10. 第六章 对象作用域与servlet事件监听器