E. The Values You Can Make
 
 

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
题意:
 
  给你n个数,k,问你这n个数和为k的集合,其子集和有哪些
 
题解:
  设定dp[i][j]表示集合和是i,其子集j是否出现
  那么转移方程 当dp[i][j]为1,就有      dp[i+a[now]]][j]=dp[i+a[now]]][j+a[now]]];
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = +, inf = 2e9, mod = 1e9+;
vector<int >G;
int dp[N][N],n,k,a[N];
int main(){
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
dp[][]=;//和为i,j是否出现过
for(int i=;i<=n;i++)
{
for(int j=k-a[i];j>=;j--)
{
for(int x=;x<=k;x++)
{
if(dp[j][x])
dp[j+a[i]][x] = , dp[j+a[i]][x+a[i]]=;
}
}
}
for(int i=;i<=k;i++)
{
if(dp[k][i]) G.push_back(i);
}
printf("%d\n",G.size());
for(int i=;i<G.size();i++) printf("%d ",G[i]);
return ;
}

Codeforces Round #360 (Div. 2) E. The Values You Can Make DP的更多相关文章

  1. Codeforces Round #360 (Div. 2) E. The Values You Can Make 01背包

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

  2. Codeforces Round #396 (Div. 2) A B C D 水 trick dp 并查集

    A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...

  3. Codeforces Round #360 (Div. 2) D. Remainders Game 数学

    D. Remainders Game 题目连接: http://www.codeforces.com/contest/688/problem/D Description Today Pari and ...

  4. Codeforces Round #360 (Div. 2) D. Remainders Game 中国剩余定理

    题目链接: 题目 D. Remainders Game time limit per test 1 second memory limit per test 256 megabytes 问题描述 To ...

  5. Codeforces Round #360 (Div. 1) D. Dividing Kingdom II 暴力并查集

    D. Dividing Kingdom II 题目连接: http://www.codeforces.com/contest/687/problem/D Description Long time a ...

  6. Codeforces Round #360 (Div. 2) C. NP-Hard Problem 水题

    C. NP-Hard Problem 题目连接: http://www.codeforces.com/contest/688/problem/C Description Recently, Pari ...

  7. Codeforces Round #360 (Div. 2) B. Lovely Palindromes 水题

    B. Lovely Palindromes 题目连接: http://www.codeforces.com/contest/688/problem/B Description Pari has a f ...

  8. Codeforces Round #360 (Div. 2) A. Opponents 水题

    A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...

  9. Codeforces Round #360 (Div. 2) D. Remainders Game

    D. Remainders Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...

随机推荐

  1. .NET中使用Memcached的相关资源整理

    Memcached官方站点:http://www.danga.com/memcached/ Memcached Win32 1.2.6下载:http://code.jellycan.com/memca ...

  2. juery动态添加和删除

    拼语句添加框(不能删除原有的tr) //点击a标签 $("#a").on("click",function(){ var $newtr = $("&l ...

  3. destroy-method="close"的作用

    destroy-method="close"的作用是当数据库连接不使用的时候,就把该连接重新放到数据池中,方便下次使用调用.

  4. form表单那点事儿(下) 进阶篇

    form表单那点事儿(下) 进阶篇 上一篇主要温习了一下form表单的属性和表单元素,这一片主要讲解用JavaScript如何操作form. 目录: 表单操作 取值 赋值 重置 校验 提交 技巧 不提 ...

  5. PhpStorm 设置php代码格式

    phpstorm 代码格式化方法: 快捷键:Ctrl + Alt + L 设置代码样式:File -> Settings -> Code Style ->PHP 根据个人php代码规 ...

  6. phpcms某处储存型XSS(demo+本地演示)

    文章转载:http://www.myhack58.com/Article/html/3/7/2016/71726.htm 详细说明: demo+本地演示存在xss漏洞的地方在商务中心的商家资料的我的资 ...

  7. window.parent与window.openner 之前的总结

    今天总结一下js中几个对象的区别和用法: 1.首先来说说 parent.window与top.window的用法 "window.location.href","loca ...

  8. CentOS6.5以runlevel 3开机时自动连接某无线设置示例

    [参考]http://blog.csdn.net/simeone18/article/details/8580592 [方法一] 假设无线网卡代号为wlan0,无线AP的essid为:TheWiFi, ...

  9. 63.如何对单链表进行快排?和数组快排的分析与对比[quicksort of array and linked list]

    [本文链接] http://www.cnblogs.com/hellogiser/p/quick-sort-of-array-and-linked-list.html [题目] 单链表的特点是:单向. ...

  10. tomcat启动是报Multiple Contexts have a path of "/XXX"

    Eclipse集成了tomcat,启动时报如下异常: Could not publish server configuration for Tomcat v7.0 Server at localhos ...