HDU 5616 Jam's balanceJam的天平

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 MM 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的天平)的更多相关文章

  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(01背包)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5616 题目: Jam's balance Time Limit: 2000/1000 MS (Java ...

  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 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  5. hdu 5616 Jam's balance 正反背包+转换

    http://acm.hdu.edu.cn/showproblem.php?pid=5616 思路 题目中蕴含着两种需要计算的重量 1. 从所有的砝码中挑出任意种2.(转换的思想)在天平的两端都挑出这 ...

  6. HDU 5616:Jam's balance(背包DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=5616 题意:有n个物品,每个重量为w[i],有一个天平,你可以把物品放在天平的左边或者右边,接下来m个询问,问是 ...

  7. 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 ...

  8. hdu 5616 Jam's balance(dp 正反01背包)

    来自官方题解: AC代码: #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream ...

  9. HDU 5616 Jam's balance

    背包.dp[i]=1表示i这种差值能被组合出来,差值有负数,所以用sum表示0,0表示-sum,2*sum表示sum. 询问X的时候,只需看dp[sum+X]或者dp[sum-X]是否有一个为1,注意 ...

随机推荐

  1. 爬虫下载校花网美女信息-lxml

    # coding=utf-8 # !/usr/bin/env python ''' author: dangxusheng desc : 下载校花网上的个人信息:名字-学校-图片地址-点赞数 date ...

  2. mybatis中传入String类型参数的问题

    1. 出现的问题 需求是想写一个按公司名字查询公司列表的功能,最开始的代码如下 Dao层接口如下 @MyBatisDao public interface OfficeDao extends Tree ...

  3. Virtual Memory is deprecated in Redis 2.4

    在读一个源码的讲解的文章时或者读一本关于某个技术的数据集时,可能书籍的讲解是滞后的,就是没有更上最新的代码,那么就要注意了WARNING! Virtual Memory is deprecated i ...

  4. 2018-2019-2 网络对抗技术 20165321 Exp6 信息搜集与漏洞扫描

    1.实践目标 掌握信息搜集的最基础技能与常用工具的使用方法. 2.实践内容 (1)各种搜索技巧的应用 百度查找IP地址: 查了一下kali的IP地址 https://fofa.so/的使用: 查询了一 ...

  5. windows 下面安装make

    1.前面文章中已经提到了wingw32的安装,安装好之后设置相应环境变量.2.打开cmd,输入 mingw-get install mingw32-make,会进行安装.3.输入 mingw32-ma ...

  6. LeetCode-7-反转整数-c# 版本

    c# 版本 // 给定一个 32 位有符号整数,将整数中的数字进行反转. public class Solution { public int Reverse(int x) { / // 边界判断 / ...

  7. Epplus DataTable一次性导出

    public void Export() { string fileName = ""; if (string.IsNullOrEmpty(fileName) == true) { ...

  8. PYTHON装饰器用法及演变

    '''开放封闭原则: 软件一旦上线之后就应该满足开放封闭原则 具体就是指对修改是封闭的,对扩展是开放的装饰器:什么是装饰器:装饰就是修饰,器指的是工具装饰器本省可以是任意可调用的对象被装饰的对象也可以 ...

  9. WebApi接口访问异常问题。尝试创建“testController”类型的控制器时出错。请确保控制器具有无参数公共构造函数

    本来运行的好好的webAPI 接口突然报了个 :“尝试创建“testController”类型的控制器时出错.请确保控制器具有无参数公共构造函数” 错误.耗了半宿最终解决了, 原因: api控制器中引 ...

  10. HttpClient 知识点

    1. httpClient 默认超时时间是 60秒 2.httpClient 是模拟表单提交,所以服务端接口要用HttpServletRequest request 接收  例如: request.g ...