Jim has a balance and N weights. (1≤N≤20)(1≤N≤20) 
The balance can only tell whether things on different side are the same weight. 
Weights can be put on left side or right side arbitrarily. 
Please tell whether the balance can measure an object of weight M.

InputThe first line is a integer T(1≤T≤5)T(1≤T≤5), means T test cases. 
For each test case : 
The first line is NN, means the number of weights. 
The second line are NN number, i'th number wi(1≤wi≤100)wi(1≤wi≤100) means the i'th weight's weight is wiwi. 
The third line is a number MM. MM is the weight of the object being measured.OutputYou should output the "YES"or"NO".Sample Input

1
2
1 4
3
2
4
5

Sample Output

NO
YES
YES

Hint

For the Case 1:Put the 4 weight alone
For the Case 2:Put the 4 weight and 1 weight on both side
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<memory>
#include<bitset>
#include<string>
#include<functional>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL; #define MAXN 23
#define INF 0x3f3f3f3f
/*
给你一个数字M
+-x +-y 能否==M
*/
int a[MAXN], n, m;
set<int> s;
int main()
{
int T, tmp;
scanf("%d", &T);
while (T--)
{
s.clear();
scanf("%d", &n);
for (int i = ; i <= n; i++)
scanf("%d", &a[i]);
//int t1, t2;
for (int i = ; i <= n; i++)
{
set<int>::iterator e = s.end();
vector<int> t;
for (set<int>::iterator it = s.begin(); it != s.end(); it++)
{
if (!s.count(*it + a[i]))
t.push_back(*it + a[i]);
if (!s.count(abs(*it - a[i])))
t.push_back(abs(*it - a[i]));
}
s.insert(a[i]);
for (int i = ; i < t.size(); i++)
s.insert(t[i]);
}
scanf("%d", &m);
while (m--)
{
scanf("%d", &tmp);
if (s.count(tmp))
printf("YES\n");
else
printf("NO\n");
}
}
}

最新文章

  1. javascript动画系列第三篇——碰撞检测
  2. HBase的Write Ahead Log (WAL) —— 整体架构、线程模型
  3. HTML5外包团队-技术分享【使用HTML5的VIDEO标记播放RTSP视频流】
  4. Nodejs npm安装socket.io报错解决办法
  5. 再学TSQL基础--单表查询
  6. uva 437 巴比伦塔(DAG上dp)
  7. 【HTML5 4】《HTML5与CSS3权威指南》 step1 导读
  8. declare-styleable:自定义控件的属性
  9. hdu 1022
  10. GridView出现不完整--GridView删除滚动条
  11. 经典union的使用
  12. 网站优化记录-通过命令预编译Asp.net 网站,成功优化到毫秒级别。
  13. CSS选取第n个标签元素
  14. 烧写uboot和openwrt固件ARxx系列
  15. 【原创】大数据基础之Zookeeper(2)源代码解析
  16. .Net RabbitMQ之消息通信 构建RPC服务器
  17. RabbitMQ 的安装----windows环境
  18. The history of programming languages.(transshipment) + Personal understanding and prediction
  19. VS中空项目、win32项目、控制台程序的区别(转)
  20. mysql的数据类型- 特别是表示日期/时间的数据类型: 参考: http://www.cnblogs.com/bukudekong/archive/2011/06/27/2091590.html

热门文章

  1. android开发学习——facebook第三方登录,看了你不会后悔
  2. h5学习-canvas绘制矩形、圆形、文字、动画
  3. redis的安装使用以及一些常用的命令
  4. 工厂方法模式及php实现
  5. Thinkphp删除缓存
  6. axis2与eclipse的整合:开始一个简单的axis2 的demo
  7. Objective-C 里面的类对象复用小结
  8. 优雅的创建map/list集合
  9. zabbix基础安装
  10. tar (child): lbzip2: Cannot exec: No such file or directory tar (child): Error is not recoverable: exiting now tar: Child returned status 2 tar: Error is not recoverable: exiting now