HDU 5616 Jam's balance
来源:互联网 发布:洛天依黑暗五部曲 知乎 编辑:程序博客网 时间:2024/06/05 00:19
Jam's balance
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 806 Accepted Submission(s): 386
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
Recommend
hujie | We have carefully selected several similar problems for you: 5654 5653 5652 5651 5650
刚开始用DFS做的,没做出来,后来就用了DP,由于两边都可以放,所以和物品放相同的一边时相当于减,所以把01背包再反向进行一次。
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int dp[2100],wei[30],n;int main(){int t,i,num,j,m;scanf("%d",&t);while(t--){memset(dp,0,sizeof(dp));scanf("%d",&n);int sum=0;for(i=0;i<n;i++){scanf("%d",&wei[i]);sum+=wei[i];}dp[0]=1;for(i=0;i<n;i++){for(j=sum;j>=wei[i];j--){dp[j]=max(dp[j],dp[j-wei[i]]);}}for(i=0;i<n;i++){for(j=0;j+wei[i]<=sum;j++) dp[j]=max(dp[j],dp[j+wei[i]]);}scanf("%d",&m);while(m--){scanf("%d",&num);if(dp[num])printf("YES\n");elseprintf("NO\n");}}return 0;}
0 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背包)
- 书单
- spring的生命周期(参考)
- JS没有重载(读书笔记)
- AndroidStudio使用札记
- [BZOJ 1592] [Usaco2008 Feb] 路面修整
- HDU 5616 Jam's balance
- Pollard's Rho Algorithm——求正整数的质因数
- 【plan】:近几月工作计划
- CentOS install Python2.7
- The method add(Fragment) in the type ArrayList<Fragment> is not applicable for the arguments (ImageF
- 最近最久未使用(LRU)页面置换算法原理及模拟实现
- RecyclerView焦点跳转BUG优化
- hdoj 1874 畅通工程 vector邻接表测试
- 比赛记