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 x using 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

【题解】



题意:给你n个数字,和一个数字k,让你在n个数字里面选取组合s1,这个组合s1里面的所有元素的和为k,然后让你在这个和为k的组合s1里面再选若干个数字, 再组成一个组合s2,问s2的所有元素的和的可能值;要找出所有的s1然后对所有的s2找出所有的可能值;

做法:

背包问题;

设dp[i][j]表示组合s1的和为i,组合s2的和为j是否可以达到;

dp[0][0]=true;

则有

    for (int i = 1;i <= n;i++)//枚举每个数字
for (int j = k;j >= c[i];j--)//枚举s1的和
for (int l = j-c[i];l >= 0;l--)//枚举s2的和
if (dp[j-c[i]][l])//背包的转移方程
{
dp[j][l]=true;//把这个数字c[i]加到s1上就变成了j,原来的l是可行的,那么换成j,l也是可行的了。(l也是s1中几个元素选出来能够组成的和)
dp[j][l+c[i]] = true;//l再加上个c[i]也是可行的.同理因为也是原来的j-c[i]所表示的s1中选出几个元素再和c[i]加起来组成的和
}
#include <cstdio>
#include <vector> using namespace std; const int MAXN = 600; int n, k,c[MAXN];
bool can[MAXN][MAXN] = { 0 };
vector <int> a; int main()
{
//freopen("D:\\rush.txt", "r", stdin);
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++)
scanf("%d", &c[i]); can[0][0] = true;
for (int i = 1; i <= n; i++)
for (int j = k; j >= c[i]; j--)
for (int l = j - c[i]; l >= 0; l--)
if (can[j - c[i]][l])
can[j][l] = can[j][l + c[i]] = true; for (int i = 0; i <= k; i++)
if (can[k][i])
a.push_back(i); int l = a.size();
printf("%d\n", l);
for (int i = 0; i <= l - 1; i++)
printf("%d%c", a[i], i == l - 1 ? '\n' : ' '); return 0;
}

最新文章

  1. Vijos1881闪烁的繁星 [线段树]
  2. 需要安全认证的远程EJB调用示例(Jboss EAP 6.2环境)
  3. Qt 自定义 滚动条 样式(模仿QQ)
  4. JS实现星级评分
  5. Python的面向对象3
  6. 基于 Webpack &amp; Vue &amp; Vue-Router 的 SPA 初体验
  7. [javascirpt] Regex
  8. C/C++误区四:char c = getchar();
  9. 【安德鲁斯】基于脚本的数据库&amp;quot;增量更新&amp;quot;,如果不改变,每次更新java代码、!
  10. [LeetCode203]Remove Linked List Elements
  11. javascript 数据类型 -- 检测
  12. 什么是HDR?
  13. PHP+Mysql 实现数据库增删改查(原生)
  14. postman发送json请求
  15. VC++异常处理
  16. html基础-a标签-img标签-绝对/相对路径(3)
  17. OGG_Oracle GoldenGate简介(概念)
  18. SpringMVC经典系列-15对SpringMVC的总结---【LinusZhu】
  19. JavaWeb学习总结(八):HttpServletRequest对象
  20. 【javascript】javascript设计模式之工厂模式

热门文章

  1. $OEM$文件夹的使用 (By无约而来)
  2. jquery自动触发click事件
  3. 翻翻git之---闪烁动画的TextView RevealTextView
  4. mysql :Native table 'performance_schema'.'cond_instances' has the wrong structure
  5. 动态布局Cell的高度
  6. outlook vba 1
  7. 键盘钩子监测按键后,获取键码及按键名称(MFC)
  8. linux系统 wm9713声卡配置 记录
  9. WCF走你~异常篇(永久更新...)
  10. glide 安装