、附录Р程序源代码Р#include stdio.hР#define size 20 struct stacksР{Рint data[size];Рint top;Р}stack;Рvoid main()Р{Рint w[size];Рint V;Рint k=0;Рint i=0;Рint j=1;Рint number;Рint s=0;Рprintf("\n请输入可供选择装入物品的个数:");Рscanf("%d",&number);Рprintf("\n请输入各件物品的体积:");Рfor(i=0;i number;i++)Рscanf("%d",&w);Рfor(i=0;i number;i++)Рs=s+w;Рprintf("\n可供选择的物品的总体s=%d\n",s);Рprintf("\n请输入背包的总体积:");Рscanf("%d",&V);Рif(V 0||V s)Рprintf("\n输入背包体积错误");Рprintf("\n");Рfor(i=0;i number;i++)Рstack.data=0;Рstack.top=0;РdoР{Рwhile(V 0&&k=number)Р{Рif(V=w[k])Р{Рstack.data[stack.top]=k;Рstack.top++;РV-=w[k];Р}Рk++;Р}Рif(V==0)Р{Рprintf("第%d个符合条件的解:",j);Рfor(i=0;i stack.top;i++)Р{Рprintf("%d",w[stack.data]);Р}Рj++;Рprintf("\n");Р}Рk=stack.data[--stack.top];Рstack.data[stack.top]=0;РV+=w[k];Рk++;Р}while(!(stack.top==0&&k==number));Р}