#T19. 01背包问题

01背包问题

Description

A traveler has a backpack that can hold a maximum of MM kilograms. There are now nn items, with weights of W1,W2,...,WnW_1, W_2, ..., W_n and values of C1,C2,...,CnC_1, C_2, ..., C_n, respectively. The goal is to determine the maximum total value the traveler can obtain.

Input Format

  • The first line: two integers, MM (backpack capacity, M200M \leq 200) and NN (number of items, N30N \leq 30).
  • Lines 2..N+12..N+1: each line contains two integers WiW_i and CiC_i, 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