Crazy Pick-up pills

Source: Internet
Author: User

Address: http://www.luogu.org/problem/show?pid=1616

"Topic Background"

This is a crazy version of the third question of the NOIP2005 group. This is entitled to commemorate the Liyuxiang of life.

"Title description"

Liyuxiang is a gifted child whose dream is to be the greatest physician in the world. To this end, he wanted to worship the most prestigious physician in the vicinity as a teacher. In order to judge his qualifications, the physician gave him a difficult problem. The physician took him to a cave that was full of herbs, and said to him, "children, there are some different kinds of herbs in this cave, and each one takes some time, and each one has its own value." I will give you some time, during which time you can pick up some herbs. If you are a smart kid, you should be able to get the total value of the herbs that are picked up. ”
If you are Liyuxiang, can you finish the task?
The difference between this question and the original question:
1. Each type of medicine can be picked with no limit.
2. A dazzling variety of drugs, the time to take a good long ah! The master waits for the Chrysanthemum to be grateful!

"Input and output format"

Input format:

Enter the first line with two integers t (1 <= T <= 100000) and M (1 <= m <= 10000), separated by a space, T represents the total amount of time that can be used to take the medicine, and M represents the number of herbs in the cave. The next M-line consists of two integers from 1 to 10000 (including 1 and 10000), each representing the time of picking a certain herb and the value of the herb.

Output format:

The output line, which contains only an integer, represents the maximum total value of the herbal medicine that can be picked up within the prescribed time.

"Input and Output sample"

Input Sample # #:

70 371 10069) 11 2

Sample # # of output:

140
Description

For 30% of data, M <= 1000;
For all data, M <= 10000.
Come on, Liyuxiang, the first AC left for you!

Ideas

Complete knapsack problem, topic water, data also water, dynamic transfer equation: F[j]:=max (f[j],f[j-a[i]]+b[i]);

varA,b,f:Array[-100000..100000] ofLongint;//F[t] Represents the maximum value n,i,j,t,m:longint that can be obtained by T-minute;functionMax (x,y:longint): Longint;begin    ifX>y ThenExit (x)Elseexit (y);End;beginFillchar (F,sizeof (f),0);    READLN (T,M);  fori:=1  toM Doreadln (A[i],b[i]);  fori:=1  toM Do         forJ:=a[i] toT DoF[j]:=max (f[j],f[j-a[i]]+B[i]); Writeln (F[t]);End.

Crazy Pick-up pills

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.