做法:dp
思路:
- 1.因为能测范围最大是,所以大于10000的范围必定测不出
- 2.考虑每一层状态转移,如果上一层存在,那么这一层分类讨论
1)两边都不放石头,即
2)放在多的那一侧,即
3)放在少的那一侧,即
代码
// Problem: 小M和天平
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/problem/13586
// Memory Limit: 262144 MB
// Time Limit: 4000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp(aa,bb) make_pair(aa,bb)
#define _for(i,b) for(int i=(0);i<(b);i++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,b,a) for(int i=(b);i>=(a);i--)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define X first
#define Y second
#define lowbit(a) (a&(-a))
#define debug(a) cout<<#a<<":"<<a<<"\n"
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef long double ld;
const int N=110,M=10005;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
const double eps=1e-6;
const double PI=acos(-1.0);
int n;
int w[N];
bool f[N][M];
void solve(){
mst(f,0);
rep(i,1,n) cin>>w[i];
f[0][0]=1;
rep(i,1,n){
for(int j=0;j<=10000;j++){
if(f[i-1][j]){
f[i][j]=1;
f[i][j+w[i]]=1;
f[i][abs(j-w[i])]=1;
}
}
}
int m;cin>>m;
while(m--){
int k;cin>>k;
if(k>10000) cout<<"NO\n";
else{
if(f[n][k]) cout<<"YES\n";
else cout<<"NO\n";
}
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
// int t;cin>>t;while(t--)
while(cin>>n)
solve();
return 0;
}