HDOJ 5616-Jam's balance【模拟】
来源:互联网 发布:独立开发者 知乎 编辑:程序博客网 时间:2024/06/09 13:42
Jam's balance
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 188 Accepted Submission(s): 82
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.
Input
The first line is a integer T(1≤T≤5) , means T test cases.
For each test case :
The first line isN , means the number of weights.
The second line areN number, i'th number wi(1≤wi≤100) means the i'th weight's weight is wi .
The third line is a numberM .M is the weight of the object being measured.
For each test case :
The first line is
The second line are
The third line is a number
Output
You should output the "YES"or"NO".
Sample Input
121 43245
Sample Output
NOYESYESHintFor the Case 1:Put the 4 weight aloneFor the Case 2:Put the 4 weight and 1 weight on both side
Source
BestCoder Round #70
解题思路:
这道题和杭电的1709是一样的,就是砝码可以放在天枰的左右两端。
#include<stdio.h> #include<math.h> #include<string.h>#include<stdlib.h> int c1[30000],c2[30000]; int a[30000]; bool cc[30000]; int main() { int i,j,n,sum; int nn; scanf("%d",&nn); while(nn--) { scanf("%d",&n); sum=0; for(i=1;i<=n;i++) { scanf("%d",&a[i]); sum=sum+a[i]; } for(i=0;i<=sum;i++) { c1[i]=0; c2[i]=0; } c1[0]=1; for(i=1;i<=n;i++) { for(j=0;j+a[i]<=sum;j++) { if(c1[j]==1) { c2[j]=1; c2[j+a[i]]=1; c2[abs(j-a[i])]=1; } } for(j=0;j<=sum;j++) { c1[j]=c2[j]; c2[j]=0; } } int num=0; memset(cc,false,sizeof(cc)); for(i=1;i<=sum;i++) { if(c1[i]==0) { cc[i]=true; } } int wnm; scanf("%d",&wnm); while(wnm--) { int yyy; scanf("%d",&yyy); if(yyy>sum) { printf("NO\n"); continue; } if(cc[yyy]==true) { printf("NO\n"); } else { printf("YES\n"); } } } return 0; }
0 0
- HDOJ 5616-Jam's balance【模拟】
- hdoj-5616-Jam's balance
- HDOJ 5616 Jam's balance(母函数)
- hdoj 5616 Jam's balance 【母函数】
- HDOJ 5616 Jam's balance (暴力)
- hdoj Jam's balance 5616 (母函数&暴力)
- 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
- HDOJ 5615-Jam's math problem【数学】
- 一起talk C栗子吧(第一百一十五回:C语言实例--线程同步之互斥量一)
- Oracle单节点开启关闭归档日志
- 2016太原网络营销师郭文军分享网站中如何合理布局关键词?
- ios-提升之【1】-UIApplication
- HDOJ 5616-Jam's balance【模拟】
- RadioGroup方法总结
- Eclipse下通过Maven的Jetty插件运行Web工程的配置
- 2015杂谈
- Leetcode 91. Decode Ways
- Arduino接口-week3-Lesson2
- 内存管理
- Web之旅第四站——CSS(Cascading style Sheet) 层叠样式表
- KM算法