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;
}

【43.75%】【codeforces 688E】The Values You Can Make的更多相关文章

  1. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  2. codeforces 688E E. The Values You Can Make(dp)

    题目链接: E. The Values You Can Make time limit per test 2 seconds memory limit per test 256 megabytes i ...

  3. 【41.43%】【codeforces 560C】Gerald's Hexagon

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【75.28%】【codeforces 764B】Decoding

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【30.43%】【codeforces 746C】Tram

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【codeforces 757D】Felicity's Big Secret Revealed

    [题目链接]:http://codeforces.com/problemset/problem/757/D [题意] 给你一个01串; 让你分割这个01串; 要求2切..n+1切; 对于每一种切法 所 ...

  7. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  8. 【搜索】【并查集】Codeforces 691D Swaps in Permutation

    题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...

  9. 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

随机推荐

  1. HibernateCRUD基础框架(1)-实体类

    HibernateCRUD基础框架包括3篇文章,主要讲述整个CRUD基础框架的思路. 第1篇:讲述最基本的实体类,这些实体类是对SQL语言中的一些概念的封装. 第2篇:在这些实体类的基础上,开发一个& ...

  2. 防止 Chrome 屏蔽 非官方 扩展程序 教程(一)

    说明 Google Chrome,又称 Google 浏览器,是一个由 Google(谷歌)公司开发的网页浏览器.该浏览器是基于其它开源软件所撰写.包含 WebKit,目标是提升稳定性.速度和安全性. ...

  3. thinkphp3.1课程 1-2 thinkphp中入口文件的实质是什么

    thinkphp3.1课程 1-2 thinkphp中入口文件的实质是什么 一.总结 一句话总结:在thinkphp中,我们访问的始终是入口文件,并没有主动去访问任何一个其他文件,只不过在入口文件体内 ...

  4. 7.1 基础知识Android消息处理机制

    1. Android消息处理机制: Handler, MessageQueue, Looper, Thread 线程概念 : 一个应用程序运行时它的主体被称为进程, 一个进程内部可以有多个线程, 线程 ...

  5. Cmake 实现debug和release lib依赖项处理

    一.说明 最近用cmake开发东西,编译vs时候,发现debug和release版本的lib库的依赖项问题,故此小结一下.若有不对之处,还请看官多多指教. 使用的工程有自己编写的工程,也有借用第三方库 ...

  6. 【JAVA编码专题】UNICODE,GBK,UTF-8区别 分类: B1_JAVA 2015-02-10 21:07 153人阅读 评论(0) 收藏

    简单来说,unicode,gbk和大五码就是编码的值,而utf-8,uft-16之类就是这个值的表现形式.而前面那三种编码是一兼容的,同一个汉字,那三个码值是完全不一样的.如"汉"的uncode值与g ...

  7. ios开发网络学习三:NSURLConnection小文件大文件下载

    一:小文件下载 #import "ViewController.h" @interface ViewController ()<NSURLConnectionDataDele ...

  8. Hadoop配置文件 分类: A1_HADOOP 2014-08-19 12:48 1157人阅读 评论(1) 收藏

    部分内容参考:http://www.linuxqq.net/archives/964.html  http://slaytanic.blog.51cto.com/2057708/1100974/ ha ...

  9. 【Nutch2.2.1基础教程之1】nutch相关异常 分类: H3_NUTCH 2014-08-08 21:46 1549人阅读 评论(2) 收藏

    1.在任务一开始运行,注入Url时即出现以下错误. InjectorJob: Injecting urlDir: urls InjectorJob: Using class org.apache.go ...

  10. 设置secureCRT中vim的字体颜色 分类: B3_LINUX 2014-07-12 22:01 1573人阅读 评论(0) 收藏

    1.在/etc/vimrc新增以下一行 syntax on 注:上述方法对root用户无效,原因为在一般用户中,alias vi=vim,而在root用户中默认无此设置,因此若需要root用户也显示颜 ...