HDU 5616 Jam's balance
来源:互联网 发布:知乎害人 编辑:程序博客网 时间:2024/06/05 07:19
Jam's balance
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.
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.
Sample Input
121 43245
Sample Output
NOYESYES
题意:先输入一个T,是数据组数,然后输入一个砝码数N,下面输入N个砝码的质量,然后,再输入一个数M是要求秤的物体,分别输入物体质量。
枚举的方法,每个砝码都有两种情况,放与不放,放又可以分两种情况,放左边,放右边。用一个bool型数组表示现在拥有那几重质量,所有的砝码一次添加,产生新的质量存进去。
#include <cstdio>#include <algorithm>#include <cmath>#include <cstring>using namespace std;const int maxn = 2002;bool a[maxn], vis[maxn];int w[102];int main(){ int T; int n, q; scanf("%d",&T); while(T--) { scanf("%d", &n); for(int i=1; i<=n; i++) scanf("%d", &w[i]); memset(a, 0, sizeof a); memset(vis, 0, sizeof vis); a[0] = 1; for(int i=1; i<=n; i++) { memset(vis, 0, sizeof vis); for(int j=0; j<=2000; j++) { if(a[j] == 1) { if(j-w[i] >= 0) vis[j-w[i]] = 1; if(j+w[i] <= 2000) vis[j+w[i]] = 1; } } for(int j=0; j<=2000; j++) { if(vis[j]) a[j] = 1; } } scanf("%d", &q); while(q--) { int x; scanf("%d", &x); if(a[x]) printf("YES\n"); else printf("NO\n"); } } return 0;}
1 0
- HDU 5616 Jam's balance
- hdu 5616 Jam's balance
- HDU 5616 Jam's balance
- HDU 5616 Jam's balance
- HDU 5616Jam's balance
- HDU 5616 Jam's balance
- HDU 5616 Jam's balance(dp)
- hdu 5616 Jam's balance ( 动态规划 )
- hdu 5616 Jam's balance(简单dp)
- HDU 5616 Jam's balance(dp)
- HDU 5616 Jam's balance(01背包)
- HDU 5616 Jam's balance dp, bitset
- HDU-5616 Jam's balance(母函数)
- hdoj-5616-Jam's balance
- HDU 5616 Jam's balance(01背包)
- HDU 5616 Jam's balance(暴力枚举子集)
- 杭电 hdu 5616 Jam's balance【思维】【暴力枚举】
- HDU 5616 Jam's balance(01背包)
- Atom 安装包国内镜像
- kafak集群搭建与使用
- j2ee 中smb简单介绍使用
- Android Studio百度地图发布版SHA1的获取
- Android-25种开源炫酷动画框架
- HDU 5616 Jam's balance
- 欢迎使用CSDN-markdown编辑器
- deep learning with R
- LeetCode OJ 106. Construct Binary Tree from Inorder and Postorder Traversal
- 【DOM】Node类型之Element类型
- mysql中游标的使用案例详解(学习笔记)
- 为何用https
- MyCat部署运行(Windows环境)与使用步骤详解
- JS:关于JS引用类型——Function类型