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. 快速入门Maven(三)

    一.整合ssh框架的Maven项目 1.传递依赖 只添加了一个struts2-core依赖,发现项目中出现了很多jar, 这种情况叫 依赖传递 2.依赖版本冲突的解决 (1)第一声明优先原则(就是谁写 ...

  2. AutoCAD 2019 for mac 非常好用的CAD三维设计绘图软件

    macOS下用什么cad软件?mac在哪下载cad软件? AutoCAD 2019 for mac 是一款非常好用的CAD三维设计绘图软件,可应用三维建模.CAD.渲染.动画.视觉特效和数字图像. A ...

  3. jQuery v1.10.2如何判断checkbox(复选框)是否被选中

    做项目时,我们经常会用到jquery来做一些判断,今天自己遇上判断复选框是否选中,然后搜索查看,发现现在网上的都是错误的,下面罗列错误的: 1.$("#id").attr(&quo ...

  4. Centos7升级Git版本

    centos 升级 Git 版本 问题描述 centos7 系统默认的 git 安装版本是 1.8,但是在项目构建中发现 git 版本过低,于是用源码编译的方式进行升级.同时该文章也适用于安装新的 g ...

  5. CDN实现原理

    避让:尽可能避开互联网上有可能影响数据传输速度和稳定性的瓶颈和环节,使内容传输的更快.更稳定. 检测:通过在网络各处放置节点服务器所构成的在现有的互联网基础之上的一层智能虚拟网络,CDN系统能够实时监 ...

  6. 【Java必修课】ArrayList与HashSet的contains方法性能比较(JMH性能测试)

    1 简介 在日常开发中,ArrayList和HashSet都是Java中很常用的集合类. ArrayList是List接口最常用的实现类: HashSet则是保存唯一元素Set的实现. 本文主要对两者 ...

  7. php反序列化漏洞复现过程

    PHP反序列化漏洞复现 测试代码 我们运行以上代码文件,来证明函数被调用: 应为没有创建对象,所以构造函数__construct()不会被调用,但是__wakeup()跟__destruct()函数都 ...

  8. sublime设置 reindent 快捷键

    设置快捷键 使用快捷键 cmd + shift + p 打开控制面板 输入 key 关键词 点击进入 Key Bindings -User 添加如下代码 { "keys": [&q ...

  9. 2018.8.2 python中is和==的区别

    一.is 和==的区别 1.is 比较的是左右两边的内存地址, ==比较的是左右两边的值. 2.id() 通过id()可以查看一个变量表示的值得内存中的地址. s = 'alex' s1 = 'ale ...

  10. JVM三部曲之运行时数据区 (第一部)

    在接下来的几天想总结下,JVM相关的一些内容,比如下面的这三个内容算是比较核心知识点了 1.运行时数据区域: 在运行时数据区里存储类Class文件元数据(方法区),对象和数组(堆),方法参数局部变量( ...