Lab 5: Sorting of backpack problems and time-bound jobs, and time-limit of backpacks

Source: Internet
Author: User

Lab 5: Sorting of backpack problems and time-bound jobs, and time-limit of backpacks

I. Experiment Name: Sorting of backpack problems and time-bound jobs

Ii. Tutorial purpose: to master the ideas and general processes of greedy algorithms for solving problems and learn to use greedy algorithms to solve practical problems.

Iii. experiment content

Lab problems and program running results:

Part 1 backpack Problems

1. Analyze programs 6-1 on page 1 and draw a flowchart.

2. Analyze the Knapsack class and private variables, which respectively indicate the following meanings:

3. Analyze the greedyKnapsack program and draw a flowchart of the algorithm.

4. When the backpack is:

W

18

15

10

P

25

24

15

M = 20:

The output of the solution array is:

5. Improve the greedyKnapsack program so that the output solution array is the same as the original sequence. When the backpack value is:

W

8

2

25

7

4

7

4

P

10

5

11

15

3

13

1

When M = 45, the output of the solution array is:

 

Part 2 time-bound job Sorting Algorithm

Time Limit

2

1

2

4

3

Value

100

10

15

27

9

The final result of the greedy algorithm is:

 

Iv. Experiment summary and experiences:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.