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. tf.split

    tf.split(dimension, num_split, input):dimension的意思就是输入张量的哪一个维度,如果是0就表示对第0维度进行切割.num_split就是切割的数量,如果是 ...

  2. oracle弱口令攻击

    oracle弱口令攻击   0x00 oracle数据库简介 oracle数据库是现在很流行的数据库系统,很多大型网站都采用Oracle,它之所以倍受用户喜爱是因为它有以下突出的特点: 一.支持大数据 ...

  3. Pathon中numpy模块

    目录 numpy模块 切割矩阵 矩阵元素替换 矩阵的合并 通过函数创建矩阵 fromstring/fromfunctions 矩阵的运算 常用矩阵运函数 矩阵的点乘 矩阵的逆 矩阵的其他操作 nump ...

  4. 12.Linux重定向与管道|

    1.重定向概述 1.1什么是重定向 将原本要输出到屏幕的数据信息,重新定向到某个指定的文件中 名称 文件描述符 作用 标准输入(STDIN) 0 默认是键盘,也可以是文件或其他命令的输出. 标准输出( ...

  5. 百万年薪python之路 -- socket粘包问题解决

    socket粘包问题解决 1. 高大上版解决粘包方式(自定制包头) 整体的流程解释 整个流程的大致解释: 我们可以把报头做成字典,字典里包含将要发送的真实数据的描述信息(大小啊之类的),然后json序 ...

  6. Java描述设计模式(16):代理模式

    本文源码:GitHub·点这里 || GitEE·点这里 一.生活场景 1.场景描述 在电商高速发展的今天,快递的数量十分庞大,甚至出现了快递代理行业,简单的说就是快递的主人没有时间收快递,会指定一个 ...

  7. (七)javac编译

    文章目录 1.基本格式 2.目标路径 2.1 缺省项 2.2 指定路径 2.2.1 全路径 2.2.2 相对路径 3.源文件 3.1 无第三方库 3.1.1 基本方法 3.1.2 添加目录 3.1.3 ...

  8. 判断是否存在UI被触摸

    ) || (Input.touchCount > && Input.GetTouch().phase == TouchPhase.Began)) { #if UNITY_ANDR ...

  9. 如何理解swift中的delegate

    Delegation翻译为代理或者委托,是一种设计模式.顾名思义,使class或struct能够将某些职责移交给其他类型的实例. 该设计模式通过定义一个封装(包含)delegate的protocol( ...

  10. spring boot 面试题详解

    1.什么是springboot 用来简化spring应用的初始搭建以及开发过程 使用特定的方式来进行配置(properties或yml文件) 创建独立的spring引用程序 main方法运行 嵌入的T ...