Jam's balance set 暴力
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 暴力的更多相关文章
- HDU 5616 Jam's balance(DP)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5616 题目: Jam's balance Time Limit: 2000/1000 MS (Java ...
- HDU 5616 Jam's balance(Jam的天平)
HDU 5616 Jam's balance(Jam的天平) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K ...
- 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 ...
- HDU 5616 Jam's balance(01背包)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5616 题目: Jam's balance Time Limit: 2000/1000 MS (Java ...
- 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 ...
- hdu 5616 Jam's balance(dp 正反01背包)
来自官方题解: AC代码: #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream ...
- HDU 5616 Jam's balance
背包.dp[i]=1表示i这种差值能被组合出来,差值有负数,所以用sum表示0,0表示-sum,2*sum表示sum. 询问X的时候,只需看dp[sum+X]或者dp[sum-X]是否有一个为1,注意 ...
- hdu 5616 Jam's balance 正反背包+转换
http://acm.hdu.edu.cn/showproblem.php?pid=5616 思路 题目中蕴含着两种需要计算的重量 1. 从所有的砝码中挑出任意种2.(转换的思想)在天平的两端都挑出这 ...
- HDU 5616:Jam's balance(背包DP)
http://acm.hdu.edu.cn/showproblem.php?pid=5616 题意:有n个物品,每个重量为w[i],有一个天平,你可以把物品放在天平的左边或者右边,接下来m个询问,问是 ...
随机推荐
- php安装ionCube
- negroni-gzip源码简单分析解读
negroni-gzip源码简单分析解读 这是一个为Negroni设计的gzip压缩处理中间件,需要用到已有的compress中的gzip,阅读了不长的源码之后,总结了一些关键要点和注意点. 检查是否 ...
- 聊5块钱P2V
上一秒还在写代码,下一秒就跑机房干活. 这台机器产制石器时代,重启一次后再就启动不了了.这个故障处理的方式我们以后再谈. 今天聊聊啥是P2V,国人总喜欢弄些稀奇古怪的定义来证明自己技术很牛X,就跟当年 ...
- CentOS7.5搭建LAMP环境
导言 LAMP环境搭建,网上可以搜到很多的结果.为什么我还要整理一下呢,是因为有些网上给出的解决办法可能仅适用于某些特定的环境下,并不一定适用于所有出现问题的情况. 当然我写本篇的目的也不是保证所有的 ...
- JavaScript——class与原型对象
原型对象的意义 通过new 一个构造函数,我们能够获得一个实例,在new 的过程中,程序会在内存中申请一块区域,同时我们可以加参数,所以每个对象都不一样. 原型对象则是同一个构造函数 new 出来的所 ...
- .NET Core MVC Web最最最基础的框架搭建
1. 使用VS创建.NET Core MVC Web项目 创建完成就是酱紫的了 2. 用NuGet把这些全部都安装了 Install-Package Microsoft.EntityFramework ...
- 迅为iMX6开发板支持单核,双核,四核处理器,为客户产品选择提供灵活性
本文转自迅为:http://topeetboard.com 店铺:https://arm-board.taobao.com 处理器:Freescale Cortex-A9 四核 i.MX6Q 主频 1 ...
- 十一,类型参数化--Scala
类型参数化 在scala中,类型参数化(类似于泛型)使用方括号实现,如:Foo[A],同时,我们称Foo为高阶类型.如果一个高阶类型有2个类型参数,则在声明变量类型时可以使用中缀形式来表达,此时也称该 ...
- Java HTTP 组件库选型看这篇就够了
最近项目需要使用 Java 重度调用 HTTP API 接口,于是想着封装一个团队公用的 HTTP client lib. 这个库需要支持以下特性: 连接池管理,包括连接创建和超时.空闲连接数控制.每 ...
- js 判断访问终端类型
// 判断访问终端类型 var browser = { versions: function() { var u = navigator.userAgent, app = navigator.appV ...