HDU 5616 Jam's balance(DP)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=5616
题目:
Jam's balance
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1810 Accepted Submission(s): 754
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.
Input
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.
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main(){
int t,n,m;
int weight[];
int dp[];
int sum;
scanf("%d",&t);
while (t--) {
scanf("%d",&n);
memset(dp, , sizeof(dp));
dp[]=;
sum=;
for (int i=; i<n; i++) {
scanf("%d",&weight[i]);
sum+=weight[i];
}
sort(weight, weight+n);
for (int i=; i<n; i++) {
for (int j=sum; j>=; j--) {
if(j>=weight[i])dp[j]=max(dp[j], dp[j-weight[i]]);
else dp[j]=max(dp[j], dp[weight[i]-j]);
}
}
scanf("%d",&m);
for (int i=; i<m; i++) {
int w;
scanf("%d",&w);
printf("%s\n",dp[w]?"YES":"NO");
}
}
return ;
}
HDU 5616 Jam's balance(DP)的更多相关文章
- 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 ...
- hdu 5616 Jam's balance(dp 正反01背包)
来自官方题解: AC代码: #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream ...
- hdu 5616 Jam's balance 正反背包+转换
http://acm.hdu.edu.cn/showproblem.php?pid=5616 思路 题目中蕴含着两种需要计算的重量 1. 从所有的砝码中挑出任意种2.(转换的思想)在天平的两端都挑出这 ...
- 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 5617 Jam's maze dp+滚动数组
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5617 bc(中文):http://bestcoder.hdu.edu.cn/contest ...
- cdq分治(hdu 5618 Jam's problem again[陌上花开]、CQOI 2011 动态逆序对、hdu 4742 Pinball Game、hdu 4456 Crowd、[HEOI2016/TJOI2016]序列、[NOI2007]货币兑换 )
hdu 5618 Jam's problem again #include <bits/stdc++.h> #define MAXN 100010 using namespace std; ...
- hdu 5616
Jam's balance Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
随机推荐
- nodeJS之fs文件系统
前面的话 fs文件系统用于对系统文件及目录进行读写操作,本文将详细介绍js文件系统 概述 文件 I/O 是由简单封装的标准 POSIX 函数提供的. 通过 require('fs') 使用该模块. 所 ...
- Android WebView 不支持 H5 input type="file" 解决方法
最近因为赶项目进度,因此将本来要用原生控件实现的界面,自己做了H5并嵌入webview中.发现点击H5中 标签 不能打开android资源管理器. 通过网络搜索发现是因为 android webvie ...
- iOS中动态注入JavaScript方法。动态给html标签添加事件
项目中有这样一种需求,给html5网页中图片添加点击事件,并且弹出弹出点击的对应的图片,并且可以保持图片到本地 应对这样的需求你可能会想到很多方法来实现. 1. 最简单的方法就是在html5中添加图片 ...
- */美女镇楼/*>>>---PHP中的OOP-->面对过程与面对对象基础概念与内容--(封装、继承、多态)
前 言 OOP 学习了好久的PHP,今天来总结一下PHP中的重要成员OOP 1 面向过程&面向对象 1.专注于解决一个问题的过程.面向过程的最大特点,是由一个一个的函数去解决处理这 ...
- 文件快速删除工具, 解决你的node_modules
摘要: 还在为删除文件慢烦恼吗?强大工具dlf来帮助你.作为一名前端开发,最常见的就是node_modules,如果dependencies很多,osx系统删除还好,Windows用户就麻烦了.本文分 ...
- java 多线程基础
线程是进程内的执行单元,进程当中都有若干个线程. 通常主线程或进程是阻塞式的按顺序执行的,如果希望异步执行些子任务,而不要阻塞当前线程的执行,即需要创建子线程,子线程创建后主线程可以等待它们的结果,得 ...
- linq中给字段添加别名
linq 是我们在查询中经常回用到的一种形式,比如我们创建一个类,然后List<添加> 并绑定到表格中 public class Modeltest { string id; public ...
- [BZOJ4907]柠檬
4709: [Jsoi2011]柠檬 Time Limit: 10 Sec Memory Limit: 128 MB Description Flute 很喜欢柠檬.它准备了一串用树枝串起来的贝壳, ...
- springmvc 之 返回值
springMVC对于controller处理方法返回值的可选类型 spring mvc 支持如下的返回方式:ModelAndView, Model, ModelMap, Map,View, Stri ...
- 不小心用js重做了一遍贪吃蛇
贪吃蛇游戏想必没人会感到陌生,这个游戏的js版本在网上也是一搜一大把,今天我要介绍的仍然是如何用js做一个贪吃蛇游戏,但在关键一步,蛇的运动的实现上略有不同. 贪吃蛇的js版本通常用连续的方块元素来实 ...