题目链接:http://codeforces.com/problemset/problem/687/C

题目大概说给n个各有价值的硬币,要从它们中选出若干个组合成面值k,而要求的是各个方案里这些选出的硬币能组合出来的面值有哪些。

dp[i][j][k]表示到第i个硬币,组成面值为j,包含面值为k的方案数。

注意用滚动数组写。

 //#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int N = ;
int dp[][N][N], a[N]; int main()
{
int n, k;
scanf("%d %d", &n, &k);
for(int i = ; i <= n; ++i) {
scanf("%d", a + i);
}
dp[][][] = ;
for(int i = ; i <= n; ++i) {
for(int j = k; j >= ; --j) {
for(int x = j; x >= ; --x) {
//memset(dp[i%2], 0, sizeof(dp[i%2]));
dp[i%][j][x] |= dp[(i - )%][j][x]; //滚动数组重复使用
if(j - a[i] >= x)
dp[i%][j][x] |= dp[(i - )%][j - a[i]][x];
if(x >= a[i])
dp[i%][j][x] |= dp[(i - )%][j - a[i]][x - a[i]];
}
}
}
int cnt = , ans[];
for(int i = ; i <= k; ++i) {
if(dp[][k][i] || dp[][k][i]) {
ans[++cnt] = i;
}
}
printf("%d\n", cnt);
for(int i = ; i <= cnt; ++i) {
printf("%d%c", ans[i], i == cnt ? '\n': ' ');
}
return ;
}

Codeforces 687C. The Values You Can Make (dp)的更多相关文章

  1. Codeforces 687C The Values You Can Make(DP)

    题目大概说给n个各有价值的硬币,要从它们中选出若干个组合成面值k,而要求的是各个方案里这些选出的硬币能组合出来的面值有哪些. 有点绕.. dp[i][j][k]表示前i个硬币中 能否 组合成面值j且选 ...

  2. codeforces 687C - The Values You Can Make 简单dp

    题意:一个数组a[i],你可以挑出若干个数(只能挑一次)加起来等于k, 针对每一种方案,你可以选出这若干个数的子集来组合新数 最后所有的方案能组合出多少种数 分析:一看数据范围n,k<=500 ...

  3. CodeForces 687C The Values You Can Make

    $dp$,背包. $f[i][j][s]$表示前$i$个物品,凑出$j$价格的情况下,能否凑出$s$价格,$f[i][j][s]=1$表示能,否则不能. 转移很简单:如果$f[i][j][s]=1$, ...

  4. CodeForces 687C The Values You Can Make(动态规划)

    这个也可以说是一个01背包了,里面也有一些集合的思想在里面,首先dp方程,dp[i][j]代表着当前数值为i,j能否被构成,如果dp[i][j] = 1,那么dp[i+m][j] 和 dp[i+m][ ...

  5. Codeforces 219D. Choosing Capital for Treeland (树dp)

    题目链接:http://codeforces.com/contest/219/problem/D 树dp //#pragma comment(linker, "/STACK:10240000 ...

  6. [CodeForces - 1272D] Remove One Element 【线性dp】

    [CodeForces - 1272D] Remove One Element [线性dp] 标签:题解 codeforces题解 dp 线性dp 题目描述 Time limit 2000 ms Me ...

  7. Codeforces Round #360 (Div. 2) E. The Values You Can Make DP

    E. The Values You Can Make     Pari wants to buy an expensive chocolate from Arya. She has n coins, ...

  8. 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 ...

  9. CodeForces 687C【DP】

    题意: 给你n个数,然后让这些数相加组合,然后在这些组合的数里可以再相加组合搞出给定 k,输出这些组合的数. 思路: DP. //在枚举到第i个coin的时,dp[i][j],i 肯定能被a[i]组合 ...

随机推荐

  1. Drawable和Bitmap的区别

    Bitmap - 称作位图,一般位图的文件格式后缀为bmp,当然编码器也有很多如RGB565.RGB888.作为一种逐像素的显示对象执行效率高,但是缺点也很明显存储效率低.我们理解为一种存储对象比较好 ...

  2. 在Datatables中加入错误提示功能

    经常用Datatables的童鞋一定碰到过当采用服务端请求的时候,一旦后台出现异常,Datatables的会一直卡在那里,中间的正在处理的提示一直停留着. 为了能给用户更好的体验,需要对Datatab ...

  3. spm中头动绘图的理解,自带数据集

    1.在得到头动评估的数据基础上,可以汇出头动变化的折线图. 运行本程序需要下载相应的实例数据 headmove_data.txt 头动是fMRI的一个重要问题,该程序画出了某个被试进行扫描时头动的具体 ...

  4. erl_0011 erlang 定时器相关

    转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=20764167&id=4470124 3.1  The time ...

  5. a标签的href劫持,做判断后在跳转

    $.ajax({ type: "POST", url: "/resource/logincheck", data: {id: id}, success: fun ...

  6. uva 11752 - The Super Powers

    这个题   任意一个数,他的幂只要不是质数则可以分解成两个数的乘   判断有没有溺出  i×i  则用最大的那个数 Max/i < i 吗 #include<iostream> #i ...

  7. 【转】15 个用于 GitHub 的 Chrome 插件

    原文网址:http://webres.wang/15-useful-chrome-extensions-for-github/ 对于 GitHub 你了解多少呢?其实,它是一个基于 Git 托管的 W ...

  8. Android总结篇——Intent机制详解及示例总结

         最近在进行android开发过程中,在将 Intent传递给调用的组件并完成组件的调用时遇到点困难,并且之前对Intent的学习也是一知半解,最近特意为此拿出一些时间,对Intent部分进行 ...

  9. 纠结的ARC

    xcode不断进步,在xcode4中引入了ARC的概念.您用或者不用它就在那里,于是有了本文:如何在未使用arc的工程中引入一个使用了arc特性的文件,如何在arc工程中引用未使用arc的文件.其实说 ...

  10. mysql 1130 ERROR 1130: Host xxx.xxx.xxx.xxx is not allowed to connect to this MySQL server

    mysql -u root -p  mysql;use mysql;  mysql;select 'host' from user where user='root';  mysql;update u ...