标签:
1 class Solution { 2 public: 3 /** 4 * @param m: An integer m denotes the size of a backpack 5 * @param A: Given n items with size A[i] 6 * @return: The maximum size 7 */ 8 int backPack(int m, vector<int> A) { 9 // write your code here 10 vector<int> result(m+1, 0); 11 for (int i = 0; i < A.size(); i++) { 12 for (int j = m; j >= A[i]; j--) { 13 result[j] = max(result[j], result[j-A[i]] + A[i]); 14 } 15 } 16 return result[m]; 17 } 18 };
标签:
原文地址:http://www.cnblogs.com/shuashuashua/p/4395806.html