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");
}
}
}

Jam's balance set 暴力的更多相关文章

  1. HDU 5616 Jam's balance(DP)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5616 题目: Jam's balance Time Limit: 2000/1000 MS (Java ...

  2. HDU 5616 Jam's balance(Jam的天平)

    HDU 5616 Jam's balance(Jam的天平) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K ...

  3. HDU 5616 Jam's balance 背包DP

    Jam's balance Problem Description Jim has a balance and N weights. (1≤N≤20)The balance can only tell ...

  4. HDU 5616 Jam's balance(01背包)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5616 题目: Jam's balance Time Limit: 2000/1000 MS (Java ...

  5. Jam's balance HDU - 5616 (01背包基础题)

    Jim has a balance and N weights. (1≤N≤20) The balance can only tell whether things on different side ...

  6. hdu 5616 Jam's balance(dp 正反01背包)

    来自官方题解: AC代码: #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream ...

  7. HDU 5616 Jam's balance

    背包.dp[i]=1表示i这种差值能被组合出来,差值有负数,所以用sum表示0,0表示-sum,2*sum表示sum. 询问X的时候,只需看dp[sum+X]或者dp[sum-X]是否有一个为1,注意 ...

  8. hdu 5616 Jam's balance 正反背包+转换

    http://acm.hdu.edu.cn/showproblem.php?pid=5616 思路 题目中蕴含着两种需要计算的重量 1. 从所有的砝码中挑出任意种2.(转换的思想)在天平的两端都挑出这 ...

  9. HDU 5616:Jam's balance(背包DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=5616 题意:有n个物品,每个重量为w[i],有一个天平,你可以把物品放在天平的左边或者右边,接下来m个询问,问是 ...

随机推荐

  1. PHP使用Session遇到的一个Permission denied Notice解决办法

    搜索 session.save_path 在这里你有两个选择,一个是像我一样用; 把这一行注释掉,另一个选择就是修改一个 nobody 用户可以操作的目录,也就是说有读写权限的目录,我也查了下这个默认 ...

  2. Windows API函数大全一

    1. API之网络函数             WNetAddConnection 创建同一个网络资源的永久性连接             WNetAddConnection2 创建同一个网络资源的连 ...

  3. 11.2Java-多态

    一.父类 public class Fu { public void show(){ System.out.println("父类"); } } 二.子类 public class ...

  4. 《基于Node.js实现简易聊天室系列之引言》

    简述:这个聊天室是基于Node.js实现的,完成了基本的实时通信功能.在此之前,对node.js和mongodb一无所知,但是通过翻阅博客,自己动手基本达到了预期的效果.技术,不应该是闭门造车,而是学 ...

  5. 关于Android软键盘把布局顶上去的问题(一)

    最近接触到了一个登陆页面,布局最上面显示的是一个波纹的view,中间显示账号和密码的EditText,紧接着还有一个Button: 希望:点击EditText时,软键盘不能把波纹的view顶出去,也不 ...

  6. Node.js——Buffer

    介绍 JavaScript没有读取和操作二进制数据流的机制,但是 node.js 引入了Buffer 类型,可以操作TCP流或者文件流 使用Buffer可以用来对临时数据(二进制数据)进行存储,当我们 ...

  7. @import与link方式的区别

    1. 老祖宗的差别.link属于XHTML标签,而@import完全是CSS提供的一种方式. link标签除了可以加载CSS外,还可以做很多其它的事情,比如定义RSS,定义rel连接属性等,@impo ...

  8. Html 内联元素、外联元素 和 可变元素

    块元素(block element)一般是其他元素的容器元素 块元素一般都从新行开始,它可以容纳内联元素和其他块元素,常见块元素是段落标签'P".“form"这个块元素比较特殊,它 ...

  9. 对比props

    1.在组件中data返回数组对象 2.在父级作用域中写入 (1)prop传值 <btn-grp :buttons="buttons"></btn-grp> ...

  10. centos7下配置tomcat开机启动

    配置tomcat的开机启动1> 在centos7的/etc/rc.d/rc.local中加入:(注意自己的路径)#java environment export JAVA_HOME=/usr/j ...