/*
���环����
gcc (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
Copyright (C) 2002 Free Software Foundation, Inc.
Author��NinGoo
*/

#include <stdio.h>
#define N 6

int main(){
//��N������每��������w[k]����选取����为T�谋����卸�����选��
        int w[N]={1,8,3,4,5,2};       //6������
        int T=10;                              //����
        int k=0;                      
        int i=0;
        int j=1;
        struct stacks{                      //栈
                int s[N];
                int top;
        } the_stack;

       //��始��栈
        for(i=0;i<N;i++) the_stack.s[i]=0;
        the_stack.top=0;

        do{
                while(T>0&&k<=N){
                        if(T>=w[k]){                                          
          //��������谋����栈
                                the_stack.s[the_stack.top++]=k;
                                T-=w[k];
                        }
                        k++;                                                  
                //������蚩疾���一������
                }
                if(T==0){                                                     
           //�业�一�址��������
                        printf("------------Answer%d------------\n",j);
                        for(i=0;i<the_stack.top;i++){
                                printf("%d[%d] ",the_stack.s[i],w[the_stack.s[
i]]);
                        }
                        j++;
                        printf("\n");
                }
                k=the_stack.s[--the_stack.top];            //�也�����������前一
����栈�谋����栈���������一������
                the_stack.s[the_stack.top]=0;

                T+=w[k];
                k++;
        }while(!(the_stack.top==0&&k==N));           //��栈����k==N时�����锌���
����隙�������希��瞥�循��
}

���薪��
------------Answer1------------
0[1] 2[3] 3[4] 5[2]
------------Answer2------------
0[1] 3[4] 4[5]
------------Answer3------------
1[8] 5[2]
------------Answer4------------
2[3] 4[5] 5[2]



--


�� ��源:�����幕����� http://bbs.cqupt.edu.cn��[FROM: 172.16.37.73]