class Solution {
public:
/**
* @param m: An integer m denotes the size of a backpack
* @param A: Given n items with size A[i]
* @return: The maximum size
*/
int backPack(int m, vector<int> &A) {
// write your code here
if(m==0||A.size()==0) return 0;
vector<vector<int>> dp(A.size(),vector<int>(m+1));
for(int j=0;j<=m;j++){
dp[0][j]=A[0]<=j?A[0]:0;
}
for(int i=1;i<A.size();i++){
for(int j=0;j<=m;j++){
if(j>=A[i]) dp[i][j]=max(dp[i-1][j-A[i]]+A[i],dp[i-1][j]);
else dp[i][j]=dp[i-1][j];
}
}
return dp[A.size()-1][m];
}
};