hdu 5616
Jam's balance
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 370 Accepted Submission(s): 173
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.
, means T test cases.
For each test case :
The first line is N
, means the number of weights.
The second line are N
number, i'th number wi(1≤wi≤100)
means the i'th weight's weight is wi
.
The third line is a number M
. M
is the weight of the object being measured.
2
1 4
3
2
4
5
YES
YES
For the Case 1:Put the 4 weight alone
For the Case 2:Put the 4 weight and 1 weight on both side
#include<bits/stdc++.h>
using namespace std;
int t;
int n;
int fa[25];
map<int,int>dp1;
map<int,int>dp2;
int sum;
int m,exm;
int main()
{
while(scanf("%d",&t)!=EOF)
{
for(int i=1; i<=t; i++)
{
sum=0;
dp1.clear();
dp2.clear();
scanf("%d",&n);
for(int j=0; j<n; j++)
{
scanf("%d",&fa[j]);
sum+=fa[j];
}
dp1[0]=1;
dp1[fa[0]]=1;
for(int j=1; j<n; j++)
{
dp2.clear();
for(int k=0; k<=sum; k++)
{
if(dp1[k])
{
dp2[k]=1;
dp2[k+fa[j]]=1;
dp2[abs(k-fa[j])]=1;
}
}
for(int k=0; k<=sum; k++)
{
if(dp2[k]&&!dp1[k])
dp1[k]=1;
}
}
scanf("%d",&m);
for(int j=1; j<=m; j++)
{
scanf("%d",&exm);
if(dp1[exm])
printf("YES\n");
else
printf("NO\n");
}
}
}
return 0;
}
hdu 5616的更多相关文章
- 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)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5616 题目: Jam's balance Time Limit: 2000/1000 MS (Java ...
- 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个询问,问是 ...
- HDU 5616 Jam's balance(01背包)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5616 题目: Jam's balance Time Limit: 2000/1000 MS (Java ...
- 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 背包DP
Jam's balance Problem Description Jim has a balance and N weights. (1≤N≤20)The balance can only tell ...
- 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 ...
随机推荐
- Siki_Unity_1-1_Unity零基础入门_打砖块
1-1 Unity零基础入门 打砖块 任务1:素材源码 www.sikiedu.com/course/77 任务2:Unity介绍 王者荣耀,球球大作战等游戏都是用unity开发的 跨平台的游戏引擎 ...
- C 计算时间差
#include <stdio.h>int main(){ //新建四个变量 la 代表小时 kc代表时间 int l,k,a,c; //输入 两个时间 scanf("%d %d ...
- 剑指offer-整数中1出现的次数27
题目描述 求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没辙了. ...
- 20172330 2017-2018-1 《Java程序设计》第九周学习总结
20172330 2017-2018-1 <程序设计与数据结构>第九周学习总结 教材学习内容总结 本周的学习包括两章内容,分别为异常和递归. 异常 错误和异常都是对象,代表非正常情况或者无 ...
- Alpha冲刺——第二天
Alpha第二天 听说 031502543 周龙荣(队长) 031502615 李家鹏 031502632 伍晨薇 031502637 张柽 031502639 郑秦 1.前言 任务分配是VV.ZQ. ...
- TCP系列13—重传—3、协议中RTO计算和RTO定时器维护
从上一篇示例中我们可以看到在TCP中有一个重要的过程就是决定何时进行超时重传,也就是RTO的计算更新.由于网络状况可能会受到路由变化.网络负载等因素的影响,因此RTO也必须跟随网络状况动态更新.如果T ...
- 【PHP】- PHPStorm+XDebug进行调试图文教程
转载:https://www.cnblogs.com/LWMLWM/p/8251905.html 这篇文章主要为大家详细介绍了PHPStorm+XDebug进行调试图文教程,内容很丰富,具有一定的 ...
- oracle 11g ADG实施手册(亲测,已成功部署多次)
一:实验环境介绍 虚拟机系统: RHEL Linux 6.4(64位) 数据库版本: Oracle 11gR2 11.2.0.4 (64位) IP地址规划: 主数据库 192.168.11 ...
- Android OCR文字识别 实时扫描手机号(极速扫描单行文本方案)
身份证识别:https://github.com/wenchaosong/OCR_identify 遇到一个需求,要用手机扫描纸质面单,获取面单上的手机号,最后决定用tesseract这个开源OCR库 ...
- P2587 [ZJOI2008]泡泡堂
题目描述 第XXXX届NOI期间,为了加强各省选手之间的交流,组委会决定组织一场省际电子竞技大赛,每一个省的代表队由n名选手组成,比赛的项目是老少咸宜的网络游戏泡泡堂.每一场比赛前,对阵双方的教练向组 ...