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个询问,问是 ...
随机推荐
- time模块、datetime模块讲解
time模块清楚三种格式的时间相互转换 import time# 时间分为三种格式#1.时间戳start= time.time()time.sleep(3)stop= time.time()print ...
- [BZOJ1083][SCOI2005]繁忙的都市 最小生成树
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1083 由kruskal算法原理可知,我们对一张无向图做普通的最小生成树,连上的最后一条边就 ...
- 关于mapState和mapMutations和mapGetters 和mapActions辅助函数的用法及作用(三)-----mapGetters
简单的理解: const getters = { newCount: function(state){ return state.count += 5; } } ------------------- ...
- MFC_VS清理器
VS清理器 界面 工程目录 列表控件ID改名IDC_FILELIST 绑定变量m_FileList 属性设置Accept Files 设置True 成员添加 // 用于保存待遍历的目录 vector& ...
- Seating Arrangement
1997: Seating Arrangement Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 543 Solved: ...
- sql server数据类型与其他数据库数据类型对应关系
SELECT * FROM msdb.dbo.MSdatatype_mappings SELECT * FROM msdb.dbo.sysdatatypemappings
- selenium webdriver 常用断言
断言常用的有: assertLocation(判断当前是在正确的页面). assertTitle(检查当前页面的title是否正确). assertValue(检查input的值, checkbox或 ...
- 无法完成安装:'Cannot access storage file '/
今天自己编译了spice-protocol spice-gtk spice qemu,然后想用virsh去创建一个虚机: # virsh define demo.xml 定义域 demo(从 ...
- pycharm connect to mysql
1.download mysql installer community 5.7.20 https://dev.mysql.com/downloads/file/?id=473605 or 链接:ht ...
- extjs中Store和grid的刷新问题
问题1:Store.load() 和Store.setproxy()区别 问题2:修改后的Grid 更新: Store.reload() 问题3,store删除后刷新会出问题 Store移除一行:St ...