[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 ;}