-
Title Description:
-
Chen Chen is a very potential and gifted child, his dream is called the world's greatest physician.
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 herbs in this cave, and it takes time to pick each strain, and each plant 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 Chen Chen, can you finish this task?
-
Input:
-
The first line of input has two integers t (1 <= T <= 1000) and M (1 <= m <=), T represents the total amount of time that can be used to pick up the medicine, and M represents the number of herbs in the cave.
The next M-line consists of two integers from 1 to 100 (including 1 and 100), each representing the time of picking a herbal herb and the value of the herb.
-
Output:
-
There may be multiple sets of test data, for each set of data,
The output consists of only one row, which contains only an integer that represents the maximum total value of the herbal medicine that can be picked up within the prescribed time.
-
Sample input:
-
70 371 10069) 11 2
-
Sample output:
-
3
-
-
Source:
-
-
2008 the computer research of the graphics Laboratory of Peking University the real problem
-
Import Java.util.Scanner; public class main{public static void Main (String args[]) {Scanner cin=new Scanner (system.in); int t,m; int b,c; Int[]a=new int[10001]; int i,j,k; while (Cin.hasnext ()) {t=cin.nextint (); M=cin.nextint (); for (i=0;i<=t;i++) a[i]=0; for (i=0;i<m;i++) {c=cin.nextint (); B=cin.nextint (); if (c<=t) {for (j=t;j>=c;j--) {if (A[J]&L T A[J-C]+B) A[j]=a[j-c]+b; }}} System.out.println (A[t]); }}}/************************************************************** problem:1123 User:carvin Language:java result:accepted time:730 Ms memory:92816 kb****************************************************************/
Topic 1123: Collecting medicine