#T19. 01背包问题
01背包问题
Description
A traveler has a backpack that can hold a maximum of kilograms. There are now items, with weights of and values of , respectively. The goal is to determine the maximum total value the traveler can obtain.
Input Format
- The first line: two integers, (backpack capacity, ) and (number of items, ).
- Lines : each line contains two integers and , representing the weight and value of each item.
Output Format
A single line containing the maximum total value.
10 4
2 1
3 3
4 5
7 9
12