01knapsack_BranchAndBound

0/1 Knapsack Problem (Branch & Bound) Description

請使用 Branch and Bound 策略解決 0/1 背包問題。

Input 第一行包含兩個正整數,分別代表背包大小 ≤ 5×10^6 和物品個數 ≤ 1000,下一行開始每行包含兩個正整數,分別代表物品價值 ≤ 10^5 和物品重量 ≤ 10^5

Output 請輸出最大收益

Sample Input 1 100 10 130 23 123 23 123 20 125 22 127 22 124 17 122 23 130 17 121 23 119 21 Sample Output 1 634

Sample Input 2 1000 20 130 91 123 84 123 94 125 83 127 87 124 85 122 81 130 81 121 90 119 92 119 86 128 82 129 87 127 86 130 88 125 82 125 91 123 89 126 82 125 90 Sample Output 2 1402