Potato sacks come in different weight capacities (specified in pounds). Potatoes come in different weights. If you are given some number of potatoes of possibly different weights (specified in pounds), determine if it is possible to exactly fill a potato sack of a given capacity using some or all of the potatoes.

Input

The first line of input contains a single decimal integer P, (1≤P≤100), which is the number of data sets that follow. Each data set should be processed identically and independently.

Each data set consists of a single line of input containing 12 space separated positive integers. They are the data set number, K, followed by the capacity, CC, of the potato sack in pounds, (10≤C≤30),

followed by the weights of 10 potatoes in pounds. A potato will not weigh more than 3 pounds.

Output

For each data set there is a single line of output.

The output line consists of the data set number, K, followed by a single space, the word "YES" if the potato sack can be filled exactly to capacity C pounds or the word "NO" if it cannot be filled exactly.

样例输出

 2

1 20 3 2 1 3 3 2 3 2 1 1
2 25 3 3 3 3 3 3 3 3 3 3

样例输出

 1 YES

2 NO

idea: 简单来说,判断能否从这么多数中找能组成一个数

#include <iostream>
#include <cstring>
using namespace std;
int n, ans, k;
int a[];
bool dfs(int i, int sum)
{
if(i==)
return sum==ans;
if(dfs(i+, sum))
return true;
if(dfs(i+, sum+a[i]))
return true;
return false;
}
int main()
{
cin >> n;
for(int i=;i<=n;i++)
{
cin >> k >> ans;
for(int j=;j<;j++)
{
cin >> a[j];
}
if(dfs(, ))
printf("%d YES\n",k);
else
printf("%d NO\n",k);
}
}

source:  2018 ICPC Greater New York Regional Contest

 

Potato Sacks的更多相关文章

  1. Codeforces243C-Colorado Potato Beetle(离散化+bfs)

    Old MacDonald has a farm and a large potato field, (1010 + 1) × (1010 + 1) square meters in size. Th ...

  2. Potato(邪恶土豆)–windows全版本猥琐提权

    工作原理: Potato利用已知的Windows中的问题,以获得本地权限提升,即NTLM中继(特别是基于HTTP > SMB中继)和NBNS欺骗.使用下面介绍的技术,它有可能为一个非特权用户获得 ...

  3. Potato土豆win综合提权

    0x01 NBNS和WDAP NBNS: 在 Windows 系统中的另外一种名称就是 NetBIOS 名称,准确的说 NetBIOS 名称并非是一种名字系统,而是 Windows 操作系统网络的一个 ...

  4. Little Sub and Mr.Potato's Math Problem (构造法)

    题目传送门Little Sub and Mr.Potato's Math Problem Time Limit: 2 Seconds      Memory Limit: 65536 KB Littl ...

  5. Potato家族本地提权分析

    原文来自SecIN社区-作者:Zeva 0x00 前言 在实际渗透中,我们用到最多的就是Potato家族的提权.本文着重研究Potato家族的提权原理以及本地提权细节 0x01 原理讲解 1.利用Po ...

  6. Colorado Potato Beetle(CF的某道) & 鬼畜宽搜

    题意: 一个人在一张大图上走,给你路径与起点,求他走出的矩形面积并.(大概这个意思自行百度标题... SOL: 与其说这是一道图论题不如说是一道生动活泼的STL-vector教学.... 离散化宽搜, ...

  7. Little Sub and Mr.Potato's Math Problem-构造

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5864 思路 : 判断小于它的合法的,再看大于它的合法的,特判10000. ...

  8. (P2022 有趣的数)||(zoj Little Sub and Mr.Potato's Math Problem)(思维)

    题目链接:https://www.luogu.org/problemnew/show/P2022 题目大意:中文题目 具体思路: 第一步:我们可以先计算出当前的数前面按照字典序的话,前面有多少数(包括 ...

  9. use potato

随机推荐

  1. Flask中g对象,以及g,session,flash之间的区别

    一.g对象的使用 专门用来存储用户信息的g对象,g的全称的为global g对象在一次请求中的所有的代码的地方,都是可以使用的 g对象的使用: 设置:g.变量名= 变量值 获取:g.name 注意:g ...

  2. Python3_基础

    目录 数据类型 变量 数据类型的转换 算术操作符 输入 字符串常用方法 数据类型 我们先来看看三种常见的数据类型 字符串 str 在Python中,字符串一般都用引号引起来,不管是用单引号还是双引号都 ...

  3. PHP 组件注册的例子

    <?php namespace Test; abstract class Plugin { protected $pluginName = null; abstract public funct ...

  4. ARM64架构下,OpenJDK的官方Docker镜像为何没有8版本

    为什么需要ARM64架构的OpenJDK8的Docker镜像 对现有的Java应用,之前一直运行在x86处理器环境下,编译和运行都是JDK8,如今在树莓派的Docker环境运行(也可能是其他ARM环境 ...

  5. [USACO09JAN]安全出行Safe Travel 最短路,并查集

    题目描述 Gremlins have infested the farm. These nasty, ugly fairy-like creatures thwart the cows as each ...

  6. 如何在 Creator3D 中切换模型贴图,超级简单!

    效果预览 前两天有伙伴在 QQ 上询问,如何在 Creator 3D 中切换模型贴图.Shawn 之前也没尝试过,不过根据之前 Cocos Creator 的经验以及这几天对 Creator 3D 的 ...

  7. JavaScript中valueOf、toString的隐式调用

    今天在群上有人问这样一个问题: 函数add可以实现连续的加法运算函数add语法如下add(num1)(num2)(num3)...;//注意这里是省略号哟,无限使用举例如下:add(10)(10)=2 ...

  8. win7重装系统经验总结报告(2013年6月29日凌晨1:45)

    win7重装系统经验总结报告(2013年6月29日凌晨1:45) 步骤: 1.考虑被重做的电脑是否有重要文件在C盘.有则转移到D盘等非系统盘. 2.看该电脑是2GB内存还是4GB以上内存. 3.准备好 ...

  9. Udp 异步通信(三)

    转自:https://blog.csdn.net/zhujunxxxxx/article/details/44258719 1)服务端 using System; using System.Colle ...

  10. 在k8s上安装Jenkins及常见问题

    持续集成和部署是DevOps的重要组成部分,Jenkins是一款非常流行的持续集成和部署工具,最近试验了一下Jenkins,发现它是我一段时间以来用过的工具中最复杂的.一个可能的原因是它需要与各种其它 ...