新手求帮忙啊,程序运行出错,求高手帮忙,谢谢!
#include<stdio.h>#define MAXSIZE 50
#define MAXS 25
int w[MAXSIZE];
knapsack(int s,int m)
{
typedef struct{
int s;
int m;
}stackelem;
stackelem stack[MAXS];
int i,t,top,nofail;
t=0;
top=0;
nofail=1;
while((s!=t) && nofail)
{
if((s>=t+w[1]) && (m>0))
{
stack[top].s=w[m];
stack[top].m=m;
top++;
t=t+w[m];
m--;
}
else
{
if(m==0)
{
top--;
t=t-stack[top].s;
}
if(top<1) nofail=0;
else
{
top--;
m=stack[top].m-1;
t=t-stack[top].s;
}
}
}
if(s==t)
for(i=0;i<top;i++)
printf("\n%d\n",stack[i].s);
else printf("three is no any selection!");
}
int main()
{
int s,m,i;
int w[MAXSIZE];
printf("Please input an array w:\n");
scanf("%d",w);
printf("Please input a data s:\n");
scanf("%d",&s);
i=knapsack(s,m);
return i;
}