Programming packing problem solving report

Packing problem

Suppose there are N items of goods, respectively, the size s1, s2, ... si ... sN, where si is an integer satisfying 1≤si≤100. Put these items into a group of a capacity of the box 100 (No. 1-N) are. Packing method: for each item, the box-sequential scanning, sufficient to put the article into its first accommodate boxes. Writing a program that simulate this packing process, and outputs the serial number of each article of the box is located, and placing all the items required for the number of boxes.

Sample

problem:

Get the question on the ignorant, the capacity of 100 boxes of continuous use, used every time before judgment box capacity enough to hold a thing, the solution is a panel discussion, asking roommate

Problem-solving ideas:

On the title to sample, to simulate what I thought of packing, below is a schematic (a good idea to read the next Code), if readers do not understand or believe me wrong, we welcome criticism and comments!

flow chart

Core code, look at the recommendations

for(k = 0;k<N;k++)
    {
        for (i = 0;;i++)
        {
            if (box[i] >= s[k])
            {
                box[i] -= s[k];
                printf("%d %d\n", s[k], i+1);
                
                if (i+1 > b)
                    b = i+1;
                break;
            }
        }
    }
    printf("%d\n", b);

Guess you like

Origin www.cnblogs.com/ynr-/p/12046322.html