Max Sum Without Adjacent Elements
1 2 3 4 5 6 7 8 9 10 11 12 13
| #include <bits/stdc++.h>
int Solution::adjacent(vector<vector<int>> &A) { int dp = 0, dpp = 0; for(int i = 0; i < A[0].size(); i++) { int now = max(A[0][i], A[1][i]); int dppp = max(dp, dpp + now); dpp = dp; dp = dppp; } return max(dp,dpp); }
|