← 回題庫

卷別

資料結構與演算法

證明

國立臺灣大學 2025 · 考試 · 第 19 題

考科演算法

(10 points) Consider the following decision problem ODDNUMBERSUM.

ODDNUMBERSUMInput: A set of positive odd numbers SS. A target odd number kk. Question: Is there an odd number of elements in SS whose sum is exactly kk?

(a) (5 points) Prove that ODDNUMBERSUM is NP-complete.

(b) (5 points) For any set of numbers TT we define sum(T)\mathrm{sum}(T) to be the sum of all numbers in TT. Let SS and kk be the input from ODDNUMBERSUM. Define k∗=max⁡{sum(T)∣T⊆S and sum(T)≤k}k^* = \max\{\mathrm{sum}(T) \mid T \subseteq S \text{ and } \mathrm{sum}(T) \le k\} to be the largest possible subset sum among all subsets whose sum does not exceed kk.

Let ε>0\varepsilon > 0 be any sufficiently small constant. Give an algorithm that computes an (1−ε)(1-\varepsilon)-approximate solution to k∗k^*. Specifically, your algorithm should output a value kALGk_{\mathrm{ALG}} such that (1−ε)k∗≤kALG≤k∗(1-\varepsilon)k^* \le k_{\mathrm{ALG}} \le k^*. The running time of your algorithm should be a polynomial of ∣S∣|S| and 1/ε1/\varepsilon. State the algorithm as concisely and precisely as possible. You should not write anything besides the algorithm.

標準解析

AI 已複查