92. Backpack 不重复使用

int backPack(int m, vector<int> &A) { // write your code here vector<bool> dp(m + 1, 0); dp[0] = true; for(int i = 0; i < A.size(); i++){ for(int j = m; j >= A[i]; j--){ dp[j] = dp[j] || dp[j - A[i]]; } } for(int j = m; j >= 0; j--){ if(dp[j]){ return j; } } }

Comments

Popular posts from this blog

Amazon OA 763. Partition Labels

1427. Split Array into Fibonacci Sequence

05/25 周一