Problem 1.1 Given a set of n numbers ai sum up to M , and any K ≤ M , whether there is a subset of the numbers such that they sum up to (hit) K? We assume n might be as big as 1000, but M or K is not too big. From the Guide: We use a one dimensional table m[0..M], m[b] indicate whether b can be hit. Outline: Subset Sum int m[M+10]; for(i=0; i?= m[j]+1; } ans = 0; for(i=0; i?= m[i]; There are three other versions: descending, non-descending, non-increasing. You just need to change a bit in the program. The following improvement is really cute. It is a nice exercise to prove or to believe why it is correct. Outline: O(n log n) algorithm for The LIS set st; set::iterator it; ... st.clear(); for(i=0; i
Thank you for interesting in our services. We are a non-profit group that run this website to share documents. We need your help to maintenance this website.