题目链接

题意 : 给出一幅不完全的纸牌.算出哪些牌丢失了.

思路 : 算是背包一个吧。if f[j]>0  f[j+a[i]] += f[j];然后在记录一下路径。

 //
#include <stdio.h>
#include <string.h>
#include <iostream> using namespace std ; int a[] ,b[];
int dp[] ; int main()
{
int w ;
while(~scanf("%d",&w))
{
int N ;
scanf("%d",&N) ;
for(int i = ; i <= N ; i++)
scanf("%d",&a[i]) ;
memset(dp,,sizeof(dp)) ;
memset(b,,sizeof(b)) ;
dp[] = ;
for(int i = ; i <= N ; i++)
{
for(int j = w ; j >= ; j--)
{
if(dp[j] > && (j+a[i] <= w))
{
dp[j+a[i]] += dp[j] ;
if(b[j+a[i]] <= )
b[j+a[i]] = i;
}
}
}
if(dp[w] == )
printf("0\n") ;
else if(dp[w] > )
printf("-1\n") ;
else
{
int c[] ;
memset(c,,sizeof(c)) ;
for(int i = N ; i >= ; i--)
{
if(b[w] == i)
{
c[i] = true ;
w -= a[i] ;
}
}
for(int i = ; i <= N; i++)
if(c[i] == )
printf("%d ",i) ;
printf("\n") ;
}
}
return ;
}

URAL 1244. Gentlemen (DP)的更多相关文章

  1. DP URAL 1244 Gentlemen

    题目传送门 /* 题意:已知丢失若干卡片后剩余的总体积,并知道原来所有卡片的各自的体积,问丢失的卡片的id DP递推:首先从丢失的卡片的总体积考虑,dp[i] 代表体积为i的方案数,从dp[0] = ...

  2. 递推DP URAL 1244 Gentlemen

    题目传送门 /* 题意:给出少了若干卡片后的总和,和原来所有卡片,问少了哪几张 DP:转化为少了的总和是否能有若干张卡片相加得到,dp[j+a[i]] += dp[j]; 记录一次路径,当第一次更新的 ...

  3. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  4. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  5. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

  6. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  7. 初探动态规划(DP)

    学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...

  8. Tour(dp)

    Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...

  9. 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)

    .navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...

随机推荐

  1. Linux下mysql的安装和使用(C语言)

    1 mysql的安装 我使用的ubuntu在线安装,非常简单,命令为: sudo apt-get install mysql-client mysql-server 2 mysql命令集合 网络太多了 ...

  2. 生成动态前缀且自增号码的Oracle函数

    create or replace Function GetInvitationNO(prev varchar2, num1 varchar2, num2 varchar2, sessionSetti ...

  3. php取得当前访问url文件名的几种方法

    php下获取当前访问的文件名的几种方法.推荐函数:一是PHP获取当前页面的网址: dedecms用的也是这个哦. <?php //获得当前的脚本网址 function GetCurUrl() { ...

  4. 重拾C,一天一点点

    数据类型及长度 char        字符型,占用一个字节 int          整型,通常代表特定机器中整数的自然长度 short       16位 int         16位或32位 ...

  5. PHP版本中的VC6,VC9,VC11,TS,NTS区别

    以windows为例,看看下载到得php zip的文件名 php-5.4.4-nts-Win32-VC9-x86.zip VC6:legacy Visual Studio 6 compiler,是使用 ...

  6. 最新区分兼容IE6/IE7/IE8/IE9/FF的CSS HACK写法和Css if hack条件语法操作说明

    自从安装了IE8.0正式版本!木头 就对基本的几个 CSS HACK的做一下归纳!希望对网页前端布局DIV+CSS的实施者有所帮助! 本文就主要以:IE6+IE7+IE8+IE9+FF为主要研究对象 ...

  7. XAML 概述三

    通过对前面2节对XAML的介绍,我们对XAML有了一定的认识.这一节我们来简单了解一下部分XAML命名空间(x:)语言功能. x命名空间映射的是http://schemas.microsoft.com ...

  8. 1102. Invert a Binary Tree (25)

    The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrote ( ...

  9. 绘制dot 图

    常用参数 格式:dot -T<type> -o<outfile> <infile.dot> 输入文件是<infile.dot>,生成的格式由<ty ...

  10. 8、WPF体系架构和运行机制

    体系架构:http://msdn.microsoft.com/zh-cn/library/ms750441.aspx 运行机制:http://www.cnblogs.com/leep2007/arch ...