Codeforces Round #360 (Div. 2) E. The Values You Can Make DP
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.
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.
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.
6 18
5 6 1 10 12 2
16
0 1 2 3 5 6 7 8 10 11 12 13 15 16 17 18
#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的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #360 (Div. 2) D. Remainders Game 数学
D. Remainders Game 题目连接: http://www.codeforces.com/contest/688/problem/D Description Today Pari and ...
- Codeforces Round #360 (Div. 2) D. Remainders Game 中国剩余定理
题目链接: 题目 D. Remainders Game time limit per test 1 second memory limit per test 256 megabytes 问题描述 To ...
- 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 ...
- Codeforces Round #360 (Div. 2) C. NP-Hard Problem 水题
C. NP-Hard Problem 题目连接: http://www.codeforces.com/contest/688/problem/C Description Recently, Pari ...
- Codeforces Round #360 (Div. 2) B. Lovely Palindromes 水题
B. Lovely Palindromes 题目连接: http://www.codeforces.com/contest/688/problem/B Description Pari has a f ...
- Codeforces Round #360 (Div. 2) A. Opponents 水题
A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...
- 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 ...
随机推荐
- Visual Studio Online Integrations
...
- WPF 窗体拖转时不触发MouseLeftButtonUpEvent
解决方案:手动添加Handler,因为e.Handled这个属性是用在路由事件中的,当某个控件得到一个RoutedEvent,就会检测Handled是否为true,为true则忽略该事件. //手动注 ...
- php 开启curl,重启php-fpm服务
1,找到php.ini配置 find / -name 'php.ini' /usr/local/php/etc/php.ini 找到extension=php_curl.dll 把前面的分号去掉即可. ...
- 用python写一个hello world程序
1,http://www.python.org/download/ 下载windows安装包, 2,python环境变量配置 (1)设置环境变量:我的电脑-右键-属性-高级-环境变量 在Path中加入 ...
- Insertion Sort List
对链表进行插入排序,比对数组排序麻烦一点. ListNode *insertSortList(ListNode *head) { ListNode dummy(-); for (ListNode *c ...
- BZOJ 1004
一道奇怪的数学题.为了这道题我看了很多题解,到底还是一知半解..整个感觉就是上了一场数学课. HNOI2008 Cards 题目描述 小春现在很清闲,面对书桌上的N张牌,他决定给每张染色,目前小春只有 ...
- PHP编译支持mysqli
PHP编译支持mysqli前提是必须安装mysql直接上命令先进入源码包我的源码包是在/usr/local/php-5.2.1/ext/mysqli这样进入 cd /usr/local/php-5.2 ...
- Controller之间传递数据:Block传值
http://itjoy.org/?p=420 前边我们介绍过属性传值和协议传值,这里介绍一下块传值,块类似于C中的函数指针.在Controller中传递数据非常方便,还是继续上一章的例子,将数据从S ...
- SpringMVC请求处理流程
从web.xml中 servlet的配置开始, 根据servlet拦截的url-parttern,来进行请求转发 Spring MVC工作流程图 图一 图二 Spring工作流程描述 ...
- 玩转ubuntu FAQ
一.用wubi安装ubuntu的时候自动重新下载 1.双击ubuntu.ios让windows加载这个镜像 2.断开网络 二.安装其他程序时提示Error: Dependency is not sat ...