题目链接: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. checkbox美化;给div加上checked属性

    DIV的背景图修改 $("#isOpenmibao").css("backgroundImage", " url('../images/checkbo ...

  2. myeclipes准备工作

    设置jsp中默认编码为utf-8

  3. aspose.word 在书签处插入符号

    doc.Range.Bookmarks["CBJYQQDFS110"].Text = ""; Aspose.Words.DocumentBuilder buil ...

  4. (win+linux)双系统,删除linux系统的条件下,删除grub引导记录,恢复windows引导

    //(hdx,y) (显示查找到的分区号)第一个数字指第几个硬盘,第二个指第几个分区.   一般我们是(hd0,0) \n Linux的分区已经被你从Windows中删除,系统启动后停在“grub&g ...

  5. java批量插入或更新的问题

    在批量插入或者更新中,setXXX的时候字段类型必须一致.例如:在普通sql中 pstmt8.setBigDecimal(j ,xxx);可以写成pstmt8.setString(j,xxx.toSt ...

  6. 关于div居中

    margin : 100px; margin-left: auto; margin-right: auto; 这样子设置css样式就可以实现一个div居中

  7. Twitter Storm: storm的一些常见模式

    这篇文章列举出了storm topology里面的一些常见模式: 流聚合(stream join) 批处理(Batching) BasicBolt 内存内缓存 + fields grouping 组合 ...

  8. win下 golang 跨平台编译

    mac 下编译其他平台的执行文件方式请参看这篇文章,http://www.cnblogs.com/ghj1976/archive/2013/04/19/3030703.html  本篇文章是win下的 ...

  9. ChromePHP - Chrome浏览器下的PHP debug工具

    一款 Chrome 下用来配合调试 PHP 的工具,看官方介绍应该和 FirePHP 有异曲同工的.喜欢用Chrome 的PHPer 可以尝试一下. 官方网站:http://www.chromephp ...

  10. 镜头覆盖范围FOV 的规划与FOV去四角

    本文纲要: 规划FOV的原因 FOV去四角 简单的声明 FOV查找思路 查找FOV的代码 TNoFourCornersRect结构及Contains函数 判断两个矩形是否相交 延伸与拓展 本文内容: ...