#include #include #include #define TRUE 1 #define FALSE 0 #define MAX_PEOPLE 6 #define MAX_TREASURES 8 #if !defined (MAX_INT) #define MAX_INT 80000 #endif void main (void) { FILE *infile, *outfile; unsigned long int NumTreasures, NumPeople; unsigned long int TreasureMatrix[MAX_PEOPLE][MAX_TREASURES]; unsigned long int BestPersonForTreasure[MAX_TREASURES]; unsigned long int BestTotalForPerson[MAX_PEOPLE]; unsigned long int PossiblePersonForTreasure[MAX_TREASURES]; unsigned long int PossibleTotalForPerson[MAX_PEOPLE]; unsigned long int BestDifference; unsigned long int max,min; unsigned long int add,carry,stop; unsigned long int t,p,i,j; unsigned long int num_solutions; char buffer[100]; /* Open the input and output files */ infile = stdin; outfile = stdout; /* Process the input sets */ while (TRUE) { /* Get the "START" */ fscanf(infile,"%s",&buffer); if (feof(infile)) break; /* Get the number of treasures */ fscanf(infile,"%ld",&NumTreasures); /* Get the number of people */ fscanf(infile,"%ld",&NumPeople); /* Get the treasure values */ for (p=0; p max) { max = PossibleTotalForPerson[p]; } if (PossibleTotalForPerson[p] < min) { min = PossibleTotalForPerson[p]; } } if ((max-min) < BestDifference) { num_solutions = 1; BestDifference = max-min; for (p=0; p 1) { fprintf(outfile,"Data set has %ld optimal solutions!\n",num_solutions); } /* Output the optimal solution */ for (p=0; p