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. 1
  2. 2
  3. 1 4
  4. 3
  5. 2
  6. 4
  7. 5

Sample Output

  1. NO
  2. YES
  3. YES

Hint

  1. For the Case 1:Put the 4 weight alone
  2. For the Case 2:Put the 4 weight and 1 weight on both side
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<cstring>
  5. #include<sstream>
  6. #include<algorithm>
  7. #include<queue>
  8. #include<vector>
  9. #include<cmath>
  10. #include<map>
  11. #include<stack>
  12. #include<set>
  13. #include<memory>
  14. #include<bitset>
  15. #include<string>
  16. #include<functional>
  17. using namespace std;
  18. typedef long long LL;
  19. typedef unsigned long long ULL;
  20.  
  21. #define MAXN 23
  22. #define INF 0x3f3f3f3f
  23. /*
  24. 给你一个数字M
  25. +-x +-y 能否==M
  26. */
  27. int a[MAXN], n, m;
  28. set<int> s;
  29. int main()
  30. {
  31. int T, tmp;
  32. scanf("%d", &T);
  33. while (T--)
  34. {
  35. s.clear();
  36. scanf("%d", &n);
  37. for (int i = ; i <= n; i++)
  38. scanf("%d", &a[i]);
  39. //int t1, t2;
  40. for (int i = ; i <= n; i++)
  41. {
  42. set<int>::iterator e = s.end();
  43. vector<int> t;
  44. for (set<int>::iterator it = s.begin(); it != s.end(); it++)
  45. {
  46. if (!s.count(*it + a[i]))
  47. t.push_back(*it + a[i]);
  48. if (!s.count(abs(*it - a[i])))
  49. t.push_back(abs(*it - a[i]));
  50. }
  51. s.insert(a[i]);
  52. for (int i = ; i < t.size(); i++)
  53. s.insert(t[i]);
  54. }
  55. scanf("%d", &m);
  56. while (m--)
  57. {
  58. scanf("%d", &tmp);
  59. if (s.count(tmp))
  60. printf("YES\n");
  61. else
  62. printf("NO\n");
  63. }
  64. }
  65. }

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. Docker Java+Tomcat 环境搭建

    软件环境:jdk.tomcat.docker.centos.虚拟机 首先,您要准备一个 CentOS 的操作系统,虚拟机也行.总之,可以通过 Linux 客户端工具访问到 CentOS 操作系统就行. ...

  2. Safari兼容之new Date()格式问题

    safari浏览器: 故: Safari浏览器应该用‘2017/10/23’来代替‘2017-10-23’ 谷歌浏览器: 谷歌浏览器两种格式都支持

  3. 详解Android Activity启动模式

    相关的基本概念: 1.任务栈(Task)   若干个Activity的集合的栈表示一个Task.   栈不仅仅只包含自身程序的Activity,它也可以跨应用包含其他应用的Activity,这样有利于 ...

  4. 11 Hash tables

    11 Hash tables    Many applications require a dynamic set that supports only the dictionary operatio ...

  5. R Programming week 3-Debugging

    Something’s Wrong! Indications that something’s not right message: A generic notification/diagnostic ...

  6. Jquery+ashx实现Ajax

    一 Ajax的实现方式 1.使用一般的webform,在页面用jQuery ajax调用,再从取得的html数据中取得<body>内的内容,写入DOM 优点:不用改变现有的asp.net开 ...

  7. bat批处理如何删除本地策略里的用户权限分配中的拒绝从网络访问本机项的guest用户?

    echo [Version]>mm.inf echo signature="$CHICAGO$">>mm.inf echo Revision=1>>m ...

  8. vba,excel,身份证,照片

    Sub 插入图片() '调整单元格大小,以适应图片大小 功能 插入身份证照片打印 - 正面在单元格d6       反面单元格d10 ActiveSheet.Pictures.Delete '清理过期 ...

  9. JavaScript回文数

    基本解决方案 function palindrome(str) { return str.replace(/[\W_]/g, '').toLowerCase() === str.replace(/[\ ...

  10. 使用Caliburn.Micro系列1:新建项目并引入CM

    一.WPF的几个MVVM模式实现 MVVMLight:小众的平民框架,实现简单粗暴.  pass:最近更新在15年 官网: http://www.mvvmlight.net/ 最近一篇内容全面的好文: ...