Easy 2 lines of C++ code


#1

int Solution::solve(vector<vector > &A)
{
int n=A.size();
vector<vector> v(n+1,vector(3,0));
for(int i=1;i<=n;i++)
for(int j=0;j<3;j++) v[i][j]=min(v[i-1][(j+1)%3],v[i-1][(j+2)%3])+A[i-1][j];

return min(v[n][0],min(v[n][1],v[n][2]));

}