[Sicily online] 1146. Medicine collection (0-1 backpack)

Source: Internet
Author: User
/* Constraintstime limit: 1 secs, memory limit: 32 mbdescription Chen is a gifted 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? The first line of input has two integers t (1 <= T <= 1000) and M (1 <= m <= 100), which are 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. The output includes one line. This line contains only one integer, indicating the maximum total value of herbs that can be acquired within the specified time. Sample input70 371 10069 11 2 Sample output3 */# include <iostream> # include <set> # include <vector> using namespace STD; typedef struct drug {int time; int price ;} drug; int main () {int T, M; CIN> T> m; vector <drug> data (m); For (INT I = 0; I <m; I ++) CIN> data [I]. time> data [I]. price; vector <int> OP (t + 1, 0); For (INT I = 0; I <m; I ++) {for (Int J = T; j> = data [I]. time; j --) // must start from the back to the front {If (j> = data [I]. time) OP [J] = max (OP [J], OP [J-data [I]. time] + data [I]. price) ;}} cout <op [T] <Endl ;}

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.