[Getting Started] medicine collection

Source: Internet
Author: User

[Description]

Chen is a talented child. His dream is to become the greatest physician in the world. To this end, he wants to worship the most prestigious physicians nearby. In order to judge his qualifications, the physician gave him a difficult problem. The doctor took him to a cave where herbs were everywhere and said to him, "Child, there are some different herbs in this cave. It takes some time to pick every plant, each strain also has its own value. I will give you some time, during which you can collect some herbs. If you are a smart child, you should be able to maximize the total value of collected herbs ."
If you are Chen, can you complete this task?

[Input format]

The first line of the input file contains two integers, t (1 <= T <= 1000) and M (1 <= m <= 100), separated by a space, t represents the total time that can be used for medicine collection, and m represents the number of herbs in the cave. The next line of M contains two integers ranging from 1 to 100 (including 1 and 100), indicating the time to pick a particular herb and the value of this herb, respectively.

[Output format]

The output file contains one line. This line contains only one integer, indicating the maximum total value of herbs that can be acquired within the specified time.

[Example input]

70 3
71 100
69 1
1 2
[Sample output]

3

[Analysis]

01 backpack, above.

 
# Include <stdio. h> # define maxt 1010int f [maxt]; int T, M, V, W; int main () {scanf ("% d", & T, & M); For (INT I = 1; I <= m; ++ I) {scanf ("% d", & W, & V ); for (Int J = T; j> = W; -- j) if (F [J-W] + V> F [J]) f [J] = f [J-W] + V;} printf ("% d \ n", F [T]); Return 0 ;}

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.