您的位置:首页 > 其它

LintCode - Backpack II

2015-04-06 13:26 399 查看
class Solution {
public:
/**
* @param m: An integer m denotes the size of a backpack
* @param A & V: Given n items with size A[i] and value V[i]
* @return: The maximum value
*/
int backPackII(int m, vector<int> A, vector<int> V) {
// write your code here
vector<int> result(m+1, 0);
for (int i = 0; i < A.size(); i++) {
for (int j = m; j >= A[i]; j--) {
result[j] = max(result[j], result[j-A[i]] + V[i]);
}
}
return result[m];
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: