![](https://img-blog.csdn.net/20150314134211961?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbHVja2lseXdt/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
#include<stdio.h>
int
main()
{
int
m,g,t,n;
while
(
scanf
(
"%d %d"
,&m,&n)!=EOF)
{
int
x[1000],y[1000],i,j;
for
(i=0;i<n;i++)
scanf
(
"%d"
,&x[i]);
y[0]=x[0];
g=1;
t=0;
int
z;
for
(i=1;i<n;i++)
{
y[g]=x[i];
z=g+1;
for
(j=0;j<g;j++)
y[z++]=y[j]+x[i];
g=z;
}
for
(i=0;i<g;i++)
{
if
(y[i]==m)
t=1;
if
(y[i]==m)
break
;
}
if
(t)
printf
(
"YES\n"
);
else
printf
(
"NO\n"
);
}
return
0;
}
这仅仅是背包的一类问题解决,往后还会出现更多的背包问题解决。