HDU 5616 Jam's balance(Jam的天平)
HDU 5616 Jam's balance(Jam的天平)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Problem Description - 题目描述
Jim has a balance and N weights. (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.
Jim 有一个天平和N块砝码。(≤N≤)
使用天平只能得知两端质量是否相等。
砝码可以放置在左右任意一端。
判断天平能否测量质量为M的物体。
CN
Input - 输入
The first line is a integer T(1≤T≤5), 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.
第一行有一个整数T(≤T≤),表示测试用例数。
对于每组测试用例:
第一行为N,表示砝码数。
第二行有N个数,第i个数wi(≤wi≤)表示
第三行有一个整数M。M为待测物体质量。
CN
Output - 输出
You should output the "YES"or"NO".
输出"YES"or"NO"。
CN
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
例子1:一端放置4
例子2:放置4和1在同一端
CN
题解
DP水题,先算+,再算-,没了。
代码 C++
#include <cstdio>
#include <cstring>
#define MX 1500
bool dp[MX];
int main() {
int t, n, i, j, data[];
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (i = ; i < n; ++i) scanf("%d", data + i);
memset(dp, , sizeof dp); dp[] = ;
for (i = ; i < n; ++i) {
for (j = MX; ~j; --j) if (dp[j]) dp[j + data[i]] = ;
}
for (i = ; i < n; ++i) {
for (j = data[i]; j < MX; ++j) if (dp[j]) dp[j - data[i]] = ;
}
scanf("%d", &n);
for (i = ; i < n; ++i) {
scanf("%d", &j);
dp[j] ? puts("YES") : puts("NO");
}
}
return ;
}
HDU 5616 Jam's balance(Jam的天平)的更多相关文章
- 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(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
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 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- 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个询问,问是 ...
- 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,注意 ...
随机推荐
- numpy(三)
广播: x= np.arange(12).reshape((3,4)) a= np.arange(3) b=np.arange(3)[;,np.newaxis] c=a+b a,b会扩散成公共的形状进 ...
- spring-boot mybatis配置
接着我们的spring boot项目,spring boot如何使用mybatis访问数据库呢? 个人习惯使用mapper接口和xml配置sql,从pom.xml入手 1.1 添加依赖 <dep ...
- python3.6安装docx模块
1.下载 python_docx-0.8.6-py2.py3-none-any.whl 地址: http://www.lfd.uci.edu/~gohlke/pythonlibs/2.在这个网页的最下 ...
- ValueError: Variable rnn/basic_lstm_cell/kernel already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope? Originally defined at:
问题 ValueError: Variable rnn/basic_lstm_cell/kernel already exists, disallowed. Did you mean to set r ...
- 1. centos下安装docker
CentOS Docker 安装 Docker支持以下的CentOS版本: CentOS 7 (64-bit) CentOS 6.5 (64-bit) 或更高的版本 前提条件 目前,CentOS 仅发 ...
- 运行main方法找不到类
http://blog.csdn.net/chenleixing/article/details/44816629
- B/S的学习
一. B/S的概念 B/S(Brower/Server,浏览器/服务器)模式又称B/S结构,是Web兴起后的一种网络结构模式.Web浏览器是客户端最主要的应用软件. 这种模式统一了客户端,将系统功能实 ...
- 2018-2019-2 网络对抗技术 20165335 Exp3 免杀原理与实践
一.免杀原理与基础知识: (1)杀软是如何检测出恶意代码的? 检测特征码:特征码就是一般程序都不会有的代码,而后门有的那种特别的数据,而一个程序,应用有这种代码,数据的话,就直接判定为恶意代码. 主流 ...
- Windows Server 2008安装IIS 7与配置
一.安装IIS 7 1.鼠标右键[我的电脑(Computer)]→[管理(Manager)] 2.选择[角色(Roles)],右键[添加角色(Add Roles)],弹出[添加角色向导(Add Rol ...
- (2018干货系列二)最新HTML5学习路线整合
怎么学HTML5 HTML5是万维网的核心语言,标准通用标记语言下的一个应用超文本标记语言(HTML)的第五次重大修改,一方面提升了用户体验,另一方面HTML5技术跨平台,适配多终端,改变了传统开发者 ...