The main effect of the topic
Practices
The definition has a quantity limit called bulky, the rest is small pieces.
Consider the smallest volume v1.
If even v1 are bulky, DP is easy to solve.
Otherwise, consider in the v1 of the meaning of the model, the final to be pooled out of s must be s%v1.
The problem is that S%V1 does not necessarily produce s.
In fact, if you can make a x,x+v1, you can make it.
Therefore, it is possible to find out the smallest number that can be found in each mode and determine whether it can be pooled each time.
But there are big limitations that bother us. We set F[I,J] to indicate the use of the I large, to draw out in the mode of the result of the minimum number of J, this DP equation has a aftereffect.
If you use a few large layers, the process of one layer can be pushed to the next layer (plus a large) is equivalent to an initial value, the next layer within the transfer map form the shape of the ring (for the same small piece), find the minimum value of the ring, point to its edge can be deleted, you can break the loop as a chain, a simple recursive.
#include <cstdio> #include <algorithm> #define FO (i,a,b) for (i=a;i<=b;i++) #define FD (I,A,B) for (i=a;i
>=b;i--) using namespace std;
typedef long Long LL;
const int MAXN=50+10,MAXD=10000+10;
ll F[maxd][maxn],g[maxd];
BOOL Bz[maxd];
int A[MAXN];
int i,j,k,l,r,id,c,t,n,m;
ll v;
int main () {freopen ("bag.in", "R", stdin); Freopen ("Bag.out", "w", stdout);
scanf ("%d%d", &n,&m);
Fo (i,1,n) scanf ("%d", &a[i]);
scanf ("%d%d", &l,&c);
Sort (a+1,a+n+1);
Fo (i,1,n) {if (a[i]>=l) break;
t=i;
} fo (i,0,a[1]) fo (j,0,c) f[i][j]=1000000000000000005;
Fo (i,0,a[1]) g[i]=1000000000000000005;
f[0][0]=0;
g[0]=0; Fo (j,0,c) {if (j) {FD (k,n,t+1) {fo (i,0,a[1]-1) f[i][j]=min (F[I][J)
, f[((I-a[k])%a[1]+a[1])%a[1]][j-1]+ (LL) a[k]);
} FD (k,t,2) {fo (i,0,a[1]-1) bz[i]=0; FO (i,0,a[1]-1) if (!bz[i]) {r=i;id=i;
while (!bz[r]) {bz[r]=1;
if (F[r][j]<f[id][j]) id=r;
R= (R+a[k])%a[1];
} R=id;
while ((r+a[k))%a[1]!=id) {f[(r+a[k))%a[1]][j]=min (f[(r+a[k))%a[1]][j],f[r][j]+ (LL) a[k]);
R= (R+a[k])%a[1];
}} fo (i,0,a[1]-1) g[i]=min (G[i],f[i][j]);
while (m--) {scanf ("%lld", &v);
if (g[v%a[1]]<=v) printf ("yes\n"); else printf ("no\n"); }
}